How to hide php file extension with Apache2


This entry was written more than 1 year ago. Please read the article keeping in mind its age.

While ago I've done some research about this one and I found with two different way of hiding the .php file extension
  1. Use AddType to specify how each filetype should be handled:

    This way it will skip using the mod_rewrite engine thus saving some time on parsing, but you need to rename the .php file by changing its extension to .html

    # Method 1 rename .php files to .html
    # eg. script.php to script.html then
    # make all PHP code look like HTML with
    AddType application/x-httpd-php .htm .html
  2. Use mod_rewrite to rewrite the URL to point to right file.

    This method doesn't require to change the file extension.

    # Method 2 with Rewrite without renaming files
    RewriteEngine On
    RewriteRule ^([^\.\?]+)(\?.*)?$ $1.php

    Roshan's Blog also has an article about mod_rewrite with few examples of url rewriting for seo friendly URL: