Remove .PHP Extension from URL using .htaccess

We do see many PHP URLs without .php extension this can easily be achieved simply adding the following in .htaccess file.

Note: .htaccess file must be placed in the directory where PHP files are placed.

.htaccess code

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^(.*)$ $1.php #enable it <= if / is not required after URL
RewriteRule ^(.*)/$ $1.php [L] #disable it <= if / is not required after URL

After this create a file of PHP in the same folder then you can access that URL without .php extension. I have also placed slash in the end of URL if you don’t want it so simply disable last time by # comment and enable second last line by removing # before it in the above htaccess code.

Example URL with Slash:


Example URL without Slash:


Leave your comments if you find this tutorial helpful.

One thought on “Remove .PHP Extension from URL using .htaccess

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s