Remove or edit .php or .html from URL

If you are using a web server running Apache you can easily remove extensions from the url by using the Rewrite command inside of your .htaccess file.  What this allows you to do is change the URL for the asset that is being requested.  You may want to do this for a few reasons –

  1. Hide the file names.
  2. Clean up your URLs
  3. Hide the Serving Language

Removing .php

This would change http://www.example.com/index.php to http://www.example.com/index

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]

Removing .html

This would change http://www.example.com/index.html to http://www.example.com/index

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.html [NC,L]

Change .php to .html

This would change http://www.example.com/index.php to http://www.example.com/index.html

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+).html$ $1.php [NC,L]

Change .html to .php

This would change http://www.example.com/index.html to http://www.example.com/index.php

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+).php$ $1.html [NC,L]

Change .php to .butt

This would change http://www.example.com/index.php to http://www.example.com/index.butt

  1. Make (or edit) a .htaccess file in the directory of the site you want to hide the .php
  2. Paste this code
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+).butt$ $1.php [NC,L]

Another great resource
http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/

You may also like...