问题
I'm trying to find a redirect that will remove part of a query string from a URL, but leave the remaining query string.
Now I can do this fine via a single URL redirect, but there are hundreds of these URLs. So I'm trying to find a rule that might be able to do this for all of them in one fell swoop, so I don't have to make one for each and any new ones will get redirected automatically.
I'm trying to remove start=0&
from the URLs, here are some examples:
www.example.com/products.php?start=0&category=Pens%20Ballpens
redirects too:
www.example.com/products.php?category=Pens%20Ballpens
and
www.example.com/products.php?start=0&category=Jackets
redirects too:
www.example.com/products.php?category=Jackets
回答1:
Try adding this to your htaccess in the document root:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*)&?start=0(.*)$
RewriteRule ^/?products\.php$ /products.php?%1%2 [R=301,NE]
来源:https://stackoverflow.com/questions/11539981/htaccess-301-redirect-rule-to-remove-part-of-a-query-string-from-urls-but-leave