htaccess 301 redirect rule to remove part of a query string from URLs, but leave the rest

风格不统一 提交于 2019-12-11 02:25:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!