Posted By

stephcode on 02/12/11


Tagged

url path extension append


Versions (?)

Append * to extentionless URL path


 / Published in: Other
 

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

  1. I, personally, avoid using extensions like .php in my URLs. For example:
  2.  
  3. http://www.example.com/contact
  4.  
  5. http://www.example.com/contact.php
  6.  
  7. Not only does the first URL look cleaner, but if I decided to switch languages, it would be less of an issue.
  8.  
  9. So how does one implement this? Here is the .htaccess code I found works best:
  10.  
  11. # If requested URL-path plus ".php" exists as a file
  12. RewriteCond %{DOCUMENT_ROOT}/$1.php -f
  13. # Rewrite to append ".php" to extensionless URL-path
  14. RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
  15.  
  16. Source: http://www.webmasterworld.com/apache/3609508.htm
  17. answered Oct 21 '10 at 5:11
  18.  
  19.  
  20. community wiki
  21.  
  22. Adam

Report this snippet  

You need to login to post a comment.