简体   繁体   中英

Remove query strings from HTTP response status code 301 url redirections

My .htaccess file contains Rewrite URLs and HTTP response status code 301 url redirections. When I test the redirections, it adds the query string values from the old url to the end of the redirected url. How can I stop this?

My htaccess looks like this.

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]

As stated at the mod_alias doc

If the client requests http://example.com/service/foo.txt , it will be told to access http://foo2.example.com/service/foo.txt instead. This includes requests with GET parameters, such as http://example.com/service/foo.pl?q=23&a=42 , it will be redirected to http://foo2.example.com/service/foo.pl?q=23&a=42

You can change your Redirec 301 to Rewrite rules:

Instead of:

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

Use:

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]

If you don't include the QSA flag, NO query param is added to the rewrited url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM