php - htaccess 将 .htm 重写为 html 不工作

标签 php html .htaccess mod-rewrite

在我网站的 .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 响应,这是搜索引擎友好的。

此外,还有这些很棒的在线资源:

同样值得检查:

关于php - htaccess 将 .htm 重写为 html 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16144345/

相关文章:

javascript - 如何通过 javascript 从 CSS 类获取样式属性 ime-mode?

Apache .htaccess 隐藏 .php 和 .html 扩展名

http - 使用 .htaccess 强制 HTTPS 请求

php - 在 Redis 中,如果我需要具有 RPOPLPUSH 功能的排序集怎么办?

php - 在返回 "Oops! This link appears to be broken."的 PHP 404 header 之后包含

javascript - Google 登录 API - 如何使用 PHP 将某人注销?

javascript - 提交后HTML显示php代码

html - 在 Meteor 应用程序中放置苹果全屏元标记

html - svg 元素的位置

.htaccess - htaccess 将所有流量重定向到 https ://www