本文介绍了htaccess 301重定向规则,用于从URL中删除查询字符串的一部分,但保留其余部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一个重定向,该重定向将从URL中删除部分查询字符串,但保留其余的查询字符串。

I'm trying to find a redirect that will remove part of a query string from a URL, but leave the remaining query string.

现在我可以执行此操作可以通过单个URL重定向实现,但其中有数百个URL。因此,我正在尝试找到一条规则,一次就能为所有这些规则做到这一点,因此,我不必为每个规则创建一个规则,任何新规则都会自动重定向。

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.

我正在尝试从网址中删除 start = 0& ,下面是一些示例:

I'm trying to remove start=0& from the URLs, here are some examples:

www.example.com/products.php?start=0&category=Pens%20Ballpens

也重定向:

www.example.com/products.php?category=Pens%20Ballpens

www.example.com/products.php?start=0&category=Jackets

也重定向:

www.example.com/products.php?category=Jackets


推荐答案

尝试将其添加到文档根目录的htaccess中:

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]

这篇关于htaccess 301重定向规则,用于从URL中删除查询字符串的一部分,但保留其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:19