附加*到无扩展URL路径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了附加*到无扩展URL路径相关的知识,希望对你有一定的参考价值。

  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

以上是关于附加*到无扩展URL路径的主要内容,如果未能解决你的问题,请参考以下文章