1

我的.htaccess文件包含重写 URL 和 HTTP 响应状态代码 301 url 重定向。当我测试重定向时,它会将旧 url 中的查询字符串值添加到重定向 url 的末尾。我怎样才能阻止这个?

我的 htaccess 看起来像这样。

Options +FollowSymlinks
Redirect 301 /old-site/tees~1-c/blue~123-p.html test.mydomain.com/tees~1-c/blue~123-p.html
Redirect 301 /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html
Redirect 301 /old-site/content/about.html test.mydomain.com/content/about.html

RewriteEngine on
RewriteRule ^(.+)~(.+)-c/(.+)~(.+)-p\.html?$ product.php?cde=$1&cid=$2&pde=$3&pid=$4 [QSA]

RewriteRule ^(.+)~(.+)-c\.html?$ category.php?cde=$1&cid=$2&ref=%3&srt=%4&sta=%5&ppa=%6 [QSA]

RewriteRule ^content/(.+)\.html?$ info.php?seo=$1&sta=%1 [QSA]
4

1 回答 1

1

mod_alias 文档所述

如果客户端请求http://example.com/service/foo.txt,它将被告知访问http://foo2.example.com/service/foo.txt。这包括带有 GET 参数的请求,例如 http://example.com/service/foo.pl?q=23&a=42,它会被重定向到 http://foo2.example.com/service/foo.pl? q=23&a=42

您可以将Redirec 301更改为重写规则:

代替:

Redirect 301 /old-site/tees~1-c/blue~123-p.html test.mydomain.com/tees~1-c/blue~123-p.html
Redirect 301 /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html
Redirect 301 /old-site/content/about.html test.mydomain.com/content/about.html

利用:

RewriteRule /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html [L,R=301]
RewriteRule /old-site/tees~1-c.html test.mydomain.com/tees~1-c.html [L,R=301]
RewriteRule /old-site/content/about.html test.mydomain.com/content/about.html [L,R=301]

如果您不包含 QSA 标志,则不会将查询参数添加到重写的 url

于 2013-08-22T20:54:29.240 回答