Tuesday, October 8, 2013

Want to hide file extensions like .php on your website?

One of (yes, there are a few ways to do this) is to use a mod rewrite.  If you host on Linux, this should work for you.  No index on site, so you can't browse files in folders and MultiViews helps with any calls in code that need extension etc.

This should be your .htaccess file in the root:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Options -Indexes
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
# To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This will make: http://www.mywebsite.com/mypage.php  appear as: http://www.mywebsite.com/mypage

Enjoy!