在我网站的 .htaccess 文件中,我添加了以下规则以将所有扩展名为 .htm 的请求重写为 .html:
RewriteRule ^(.*)\.htm$ $1.html [NC]
我网站中的大部分 URL 都已正确重写,但以下 URL 未正确重写。我不知道为什么这个 URL 没有被重写规则捕获:
http://www.mydomain.com/view/186/4-test-limited.htm
任何帮助将不胜感激
最佳答案
您需要先激活 mod_rewrite。
尝试:
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.htm$ $1.html [R=permanent]
R=permanent
标志告诉 Apache 发出永久重定向 301 响应,这是搜索引擎友好的。
此外,还有这些很棒的在线资源:
- Tips for configuring Apache's mod_rewrite
- modrewrite.com
- Learn Apache mod_rewrite: 13 Real-world Examples
同样值得检查:
关于php - htaccess 将 .htm 重写为 html 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16144345/