How to hide php file extension with Apache2
While ago I've done some research about this one and I found with two different way of hiding the .php file extension
-
Use AddType to specify how each filetype should be handled: http://roshanbh.com.np/2008/01/hiding-php-file-extension.html
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
-
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: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html
Danilo