Remove .php extension from URL using htaccess

Hi friends, You might wonder seeing some sites will not display any .php extension even though they developed the website using normal php script.

This can be achieved using htaccess. It’s damn simple and here is the code:

The below script will change your url from:

From: http://www.yoursite.com/mysite.php
to       : http://www.yoursite.com/mysite

Save the below script as (.htaccess) and upload it in your root folder or the folder you keep all your files (also work in sub-folder too!)


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php
</IfModule>

NOTE: Better download notepad++ to save this file as .htaccess, because default notepad won’t allow it!

For your convenience I put a demo here you can check in both the ways:

with extension:
http://www.theonlytutorials.com/demo/myfile.php

without extension:
http://www.theonlytutorials.com/demo/myfile

I had put this code in the sub-folder (demo) of my site!

For your better convenience I have given the Download too!

Download

5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *