gpt4 book ai didi

regex - 使用 mod_rewrite 删除参数

转载 作者:行者123 更新时间:2023-12-01 07:39:36 25 4
gpt4 key购买 nike

我想使用 mod_rewrite 从 URL 中删除特定的查询参数。

例子:
1) 用户输入网址:

http://localhost/intra/page.htm?var1=123&var2=456&var3=789

2) mod_rewrite 删除“var2=456”

3) 新网址:
http://localhost/intra/page.htm?var1=123&var3=789

我的问题是,我只知道参数名称 (var2),而不知道值 (456),
而且我更新知道参数的顺序。它可以放在查询字符串的开头和结尾。

我将不胜感激,因为我花了很多时间在网上搜索,却没有找到任何可行的解决方案。

最佳答案

这是一个棘手的问题,因为 var2=anything真的可以出现在查询字符串中的任何地方。

此代码应该适合您:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^(.+?&|)var2=[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]

关于regex - 使用 mod_rewrite 删除参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18935020/

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