我的.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]
答案 0 :(得分:1)
如果客户请求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标记,则不会向重写的网址添加查询参数