前几天我尝试使用 [.htaccess] 代码将我的 html 页面制作成漂亮的 url:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
这对我的 html 页面很有效,但是当我访问我的站点中使用 php 的部分(特别是我的 SMF 论坛)时,它不起作用。无论如何我可以让这段代码只适用于 .html 文件,而忽略所有其他 php 文件吗?
最佳答案
您必须检查是否存在 .html
文件以在 URI 中添加 .html
:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]
关于php - 仅 .html 的漂亮网址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35465003/