htaccess 问题:从 URL 查询中删除 1(!) 参数
我的网址看起来像
page.html?L=0&a=1&b=2&c=6 或 page.html?a=1&b=2&L=0&c=6 或 page.html?a=1&b=2&c=6&L=0 我需要删除 L=0,其中 L 可以是 0 或 1。但我需要保留所有其他参数。这怎么能做到呢?
my URL looks like
page.html?L=0&a=1&b=2&c=6 OR
page.html?a=1&b=2&L=0&c=6 OR
page.html?a=1&b=2&c=6&L=0
I need to delete the L=0, where L can be either 0 or 1. But I need to keep all other params. How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个规则:
Try this rule:
好吧,我在 http://gskinner.com/RegExr/ 上玩了很多。
我根本找不到适用于所有这些情况的正则表达式:
domain.com/login.html? p1=1&p2=2&L=0&P3=3
domain.com/login.html?p1=1&p2=2&L=1&P3=3
domain.com/login.html?p1=1&p2=2&L=0
域名.com/login.html?&L=0
域名.com/login.html?L=0
domain.com/login.html?L=0&p1=1&p2=2&P3=3
最后的最佳猜测是 (.)(L=[a-zA-Z0-9]&?)( &?)(.)>>>> $1$3$4
这导致了
domain.com/login.html?p1=1&p2=2&P3=3
域名.com/login.html?p1=1&p2=2&P3=3
domain.com/login.html?p1=1&p2=2&
域名.com/login.html?&
域名.com/login.html?
domain.com/login.html?p1=1&p2=2&P3=3
我尝试的是:
- 如果 L 参数位于中间,则将其剪掉
- 如果 L 参数位于单独参数字符串的末尾,则将其截断
- 切断 L 参数和“?”如果它是唯一的参数
你能提供更多提示吗?
Ok, I played around a lot on http://gskinner.com/RegExr/.
I simply can't find a regex that works on all these cases:
domain.com/login.html?p1=1&p2=2&L=0&P3=3
domain.com/login.html?p1=1&p2=2&L=1&P3=3
domain.com/login.html?p1=1&p2=2&L=0
domain.com/login.html?&L=0
domain.com/login.html?L=0
domain.com/login.html?L=0&p1=1&p2=2&P3=3
Last best guess was (.)(L=[a-zA-Z0-9]&?)(&?)(.) >>> $1$3$4
This resulted in
domain.com/login.html?p1=1&p2=2&P3=3
domain.com/login.html?p1=1&p2=2&P3=3
domain.com/login.html?p1=1&p2=2&
domain.com/login.html?&
domain.com/login.html?
domain.com/login.html?p1=1&p2=2&P3=3
What I try is:
- Cut out the L param if it is in the middle
- Cut off the L param if it is at the end of a loner param string
- Cut off the L param AND "?" if it is the only param
Can you provide some more hints?
好吧,又是一个头痛,我终于到了。我只是在此处发布此内容,以防万一我
。htaccess 规则
说明
该规则尝试涵盖以下所有情况
L=1& amp;p1=1&p2=2&P3=3 据我所知,正则表达式的工作原理如下:
,因此替换只需要
%{REQUEST_URI}?%1% 3.
。这将剪切具有不同 L 参数选项的第二个 ( ) 组。最终结果
URL 查询字符串将被删除 L 参数,但保留其他所有内容。
有什么意见吗?如果这对您也有价值,请随意投票。
感谢所有帮助我找到正确解决方案的人!
Ok, another headache and I am finally there. I just post this here in case I
.htaccess rule
Explanation
The rule tries to cover all the following cases
As far as my knowledge goes, the regex works as follow:
Therefor the replacement only needs
%{REQUEST_URI}?%1%3
. This will cut out the second ( ) group with the different L-param options.End result
The URL query string will be stripped of the L-param, but leave everything else.
Any comments? Feel free to vote if this is valuable for you, too.
Thanks to all who helped me find the correct solution!