In this tutorial I want to explain about hiding .php extension with URL rewriting with htaccess.
What is .htaccess
An .htaccess file is a simple ASCII file and it can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer.
With an .htaccess file we can do following:
- Redirect the user to different page
- Password protect a specific directory
- Block users by IP
- Preventing hot linking of your images
- Rewrite URIs
- Specify your own Error Documents
- Disable/Enable built-in PHP functions
Hide .php extension
Open .htaccess(create new one if not exists) file from root of your website, and add the following code.
The above lines will help you to access URLs from example.com/index.php to example.com/index
If you want to remove other extension just replace php to your extension.
We can also change the .xxx extensions to .yyy extensions for example if you want to change .php to .html just add the following lines to .htaccess file.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.