How to hide the PHP extension from the URLs?

/ By Arjun / Published on April 7, 2015

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 to

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.

0 0 votes
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
kuldeep singh
kuldeep singh
6 years ago

doesn’t work in local host

6 years ago
Reply to  kuldeep singh

yes it will work

Thomas Held
Thomas Held
5 years ago
Reply to  kuldeep singh

it doesn’T work on xampp.
take a look at this german site:

Vicky Raje
Vicky Raje
5 years ago

this code not use…it says bellow same error

5 years ago
Reply to  Vicky Raje

Which error

Would love your thoughts, please comment.x