Return to Snippet

Revision: 41113
at February 12, 2011 04:06 by stephcode


Initial Code
I, personally, avoid using extensions like .php in my URLs. For example:

http://www.example.com/contact

http://www.example.com/contact.php

Not only does the first URL look cleaner, but if I decided to switch languages, it would be less of an issue.

So how does one implement this? Here is the .htaccess code I found works best:

# If requested URL-path plus ".php" exists as a file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# Rewrite to append ".php" to extensionless URL-path
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

Source: http://www.webmasterworld.com/apache/3609508.htm
answered Oct 21 '10 at 5:11

	
community wiki

Adam

Initial URL
http://stackoverflow.com/questions/72394/what-should-a-developer-know-before-building-a-public-web-site

Initial Description


Initial Title
Append * to extentionless URL path

Initial Tags
url, path, extension

Initial Language
Other