php - 仅 .html 的漂亮网址

标签 php html .htaccess pretty-urls

前几天我尝试使用 [.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/

相关文章:

php - yii2 安装 - 迁移命令不起作用

html - 为什么我的列没有扩大到容器高度?

javascript - CSS:在 100vh 的容器中动态调整字体大小

php - 如何在提交表单时检测上传的图像是否有边框

php - 在 pdo 中回显总和

html - 在图像上定位输入文本表单和提交按钮

php - 将页面重定向到根目录,但保留 URL 中的参数

wordpress - 从 HTTPS 迁移到 HTTP

apache - apache htaccess 中的 mod_expires

php - 通过 Ajax 加载重力形式会导致