Remove Extensions from Website pages

Have you ever wanted to remove the extension from your website pages such as .php, .asp etc?

Its actually easier than you think. All you need to do is create a file on the main directory of your website called .htaccess, or edit the existing .htaccess file if you already have one.

Once you have done this simple add the following code into the file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

The above code removes the file extension for you, you can still access the page using the extension if you want to.

Advantages of doing this:

- Cleaner, easier to write, easier to remember.

- More search engine friendly.

- If you decide to mix the language your pages are written in the inclusion would be seamless.

Having  adding the code into the .htaccess file simply remove the extensions from all the file paths on your website, for example change index.php to index.


Blog written by Dave

I am one of the Directors of Bytewire and I like to blog about lots of different and interesting stuff surrounding the website design and development world.


Leave your thoughts

You may use these HTML tags and attributes in your comments.