Remove File Extension Using htaccess


There are times that you don’t want to give visitors a clue what the programming language you are using. This can be easily achieved. Take a look at the code below:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /$1.php [L,QSA]

In this example, this will completely remove the file extension from your URL such as example instead of example.php

Share and Enjoy:
  • Print this article!
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

  1. #1 by Muro on December 24, 2008 - 10:38 am

    Very Usefull İnfo. I used this feaure on this site http://property.theartofbronzeland.com

  2. #2 by Dennis on January 31, 2009 - 10:47 am

    Muy bueno el codigo:

    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)$ /$1.php [L,QSA]

    Me sirve de mucho, ahora surge otra pregunta,como hago para redireccinar a una pagina de error si el visitante coloca la extencion php??

  3. #3 by David Esquivel on April 15, 2009 - 4:23 pm

    Hola Dennis.

    Porque no usas una extension .den o .d o la que se te ocurra y la configuras en tu .htaccess. Tambien funciona XD.

    Gracias por el tip!

  4. #4 by Jess on November 8, 2009 - 4:40 pm

    Muro :
    Very Usefull İnfo. I used this feaure on this site http://property.theartofbronzeland.com

    No, you didn’t.

  5. #5 by Rahul on December 7, 2009 - 4:51 am

    The example is not working for me. sorry

  6. #6 by Gio on February 26, 2010 - 8:28 pm

    The example is for rubbish

(will not be published)