0

在我的网站上创建 301 重定向时遇到问题。当我创建重定向时,浏览器显示完整的 qherysting 而不是指向页面。

例如。我想直接 /contact 到 /contact-us

我得到的是:

/联系我们?页面=联系

这是我的 .htaccess 中的代码:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteBase /

redirect 301 /contact /contact-us 
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]

任何想法为什么会发生这种情况?

4

3 回答 3

4

这是一个 mod_alias/mod_rewrite 冲突。路径处理管道分别处理这两件事。您可以坚持使用 mod_rewrite 并替换

redirect 301 /contact /contact-us 

RewriteRule ^contact$ /contact-us [L,R=301]

因此,一旦到达此处,重写将停止,并且永远不会应用最后一条规则。否则,mod_alias 将重定向 URL,但直到它通过 mod_rewrite 运行 URI 时才会重定向,因此您会得到这个全局重定向。如果你不介意尾随,您还可以将其添加到重定向目标的末尾:

redirect 301 /contact /contact-us?

这样查询字符串就不会被附加。

于 2012-08-17T10:35:50.297 回答
0
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} ^yoursite\.com [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI}


RewriteRule ^contact[/]?$ /contact-us [R=301]
RewriteRule ^([^/\.]+)[/]?$ /index.php?page=$1 [L]
于 2012-08-17T10:42:28.697 回答
0

这样做:

重定向 301 /联系http://www.domain.com/contact-us

使用完整的网址。

于 2012-08-17T10:42:38.573 回答