【发布时间】:2017-04-04 18:57:40
【问题描述】:
我想知道如何更改此网址:
http://www.example.com/category/test.php
到这个网址:
http://www.example.com/category/test/
我们不想在文件名的末尾使用任何文件扩展名(如 .html 、 .php)。有没有合适的方法来编辑基于 PHP 的网站中的 url?
【问题讨论】:
标签: php .htaccess url-rewriting
我想知道如何更改此网址:
http://www.example.com/category/test.php
到这个网址:
http://www.example.com/category/test/
我们不想在文件名的末尾使用任何文件扩展名(如 .html 、 .php)。有没有合适的方法来编辑基于 PHP 的网站中的 url?
【问题讨论】:
标签: php .htaccess url-rewriting
您正在寻找的是漂亮或干净的网址。您可以使用 Apache mod_rewrite 模块完成此操作,请参阅http://httpd.apache.org/docs/current/mod/mod_rewrite.html
有很多系统(例如 WordPress、Drupal、Expression Engine、CakePHP、ZendFramework)可以为您实现这些。如果您在 Google 或 Bing 上快速查找“Pretty or Clean URL Rewriting”,您应该会找到大量资源以适合您的项目的方式实现此功能。
这是一篇非常容易理解且重点突出的文章,请参阅 http://net.tutsplus.com/tutorials/other/using-htaccess-files-for-pretty-urls/ 或 http://docforge.com/wiki/Clean_URL
【讨论】:
重写引擎开启
RewriteCond %{REQUEST_FILENAME} !-f
重写规则 ^([^.]+)$ $1.php [NC,L]
【讨论】: