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:

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]

answered Oct 21 '10 at 5:11

community wiki


Initial URL

Initial Description

Initial Title
Append * to extentionless URL path

Initial Tags
url, path, extension

Initial Language