【问题标题】:.htaccess redirect traffic hitting .html links to TLD homepage.htaccess 将流量重定向到 TLD 主页的 .html 链接
【发布时间】:2012-02-29 00:38:27
【问题描述】:
我正在帮助客户将在网址末尾使用 .html 扩展名的旧网站迁移到正确命名的 URL 结构。我想将所有以 .html 结尾的 URL 重定向到主页。
我试过了,但没用:
RewriteRule ^(.*)\.html$ $1http://domain.org [NC]
【问题讨论】:
标签:
apache
.htaccess
mod-rewrite
redirect
【解决方案1】:
这样的东西应该适合你的需要:
RewriteEngine On
RewriteBase /
RewriteRule (.*)\.html$ / [QSA,R=301,NC,L]
【解决方案2】:
你可以这样使用:
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ([^/]+)\.html$ index.php?page=$1 [L,NC]
或永久重定向
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule (.*)\.html$ / [R=301,NC,L]
【解决方案3】:
您的问题不是很清楚,但仅基于您的代码,我认为这对您有用:
RewriteRule \.html$ http://domain.org/? [R,L,NC]
这会将每个以 .html 结尾的 URL 重定向到 http://domain.org/,甚至去除原始 URI 中的任何查询参数。