gpt4 book ai didi

regex - htaccess 从 url 中删除参数

转载 作者:行者123 更新时间:2023-12-01 11:25:28 24 4
gpt4 key购买 nike

我正在尝试从 url 中删除某些 url 参数。这些参数不再对显示的内容产生影响,但谷歌将其中的一堆编入索引。

我想将它们重定向到基本网址。
以下是示例。

来自 www.myexamplesite.com/?start=10至:www.myexamplesite.com
来自 www.myexamplesite.com/folder1/?start=10至:www.myexamplesite.com/folder1
来自 www.myexamplesite.com/folder2/?start=10至:www.myexamplesite.com/folder2
实际上我不需要任何带有参数的 url,所以我想知道是否有办法从 url 中捕获和重定向所有其他可能的参数,并且只允许我将在 htaccess 中指定的一些选定参数。

例子:
来自 www.myexamplesite.com/?param1=10至:www.myexamplesite.com
来自 www.myexamplesite.com/?param1=10&param2=20至:www.myexamplesite.com
来自 www.myexamplesite.com/folder1/?param1=10至:www.myexamplesite.com/folder1
来自 www.myexamplesite.com/folder1/?param1=10&param2=20至:www.myexamplesite.com/folder1
但是对于 param3 这应该是我选择的一个:

来自 www.myexamplesite.com/folder1/?param3=10保持原状:www.myexamplesite.com/folder1/?param3=10
更新
我实际上已经实现了一个解决方案,但我的主要问题是它总是重定向到主页而不是适当的 REQUEST_URI...

这是我所拥有的:

RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !^item=
RewriteCond %{REQUEST_URI} !^/manage
RewriteRule .? http://www.myexamplesite.com%{REQUEST_URI}? [R=301,L]

最佳答案

您可以使用此规则去除所有查询字符串,除非在其中找到 param3=

RewriteEngine On

RewriteCond %{QUERY_STRING} .
RewriteCond %{QUERY_STRING} !(?:^|&)param3= [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]

关于regex - htaccess 从 url 中删除参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37722694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com