[英]Regex rule to exclude url with specific word
When I search for " abc 920 def" on my site, the domain fires: 当我在自己的网站上搜索“ abc 920 def”时,域将触发:
http://www.domain.com/?s=abc+920+def
Then, this redirection rule: 然后,此重定向规则:
/?(.*)=(.*)920(.*)
will redirect it to a category: domain.com/all-things-920/
会将其重定向到以下类别:
domain.com/all-things-920/
The problem now is that I have some other pages that generate random numbers for receipt pages, such as: 现在的问题是,我还有其他一些页面会为收据页面生成随机数,例如:
/store/receipt/?ouid=0955a8980823k920
Because that url contains 920
, it will redirect it to the category domain.com/all-things-920/
which I don't want. 因为该URL包含
920
,它将重定向到我不想要的类别domain.com/all-things-920/
。
I tried playing with some regex combinations without any luck. 我试过一些正则表达式组合,但没有运气。 Is there a way to exclude the regex rule if the url contains
ouid
in it? 如果网址中包含
ouid
,是否可以排除正则表达式规则?
I tried: /?(?!ouid)(.*)=(.*)920(.*)
without luck. 我试过了:/?(
/?(?!ouid)(.*)=(.*)920(.*)
. /?(?!ouid)(.*)=(.*)920(.*)
. /?(?!ouid)(.*)=(.*)920(.*)
. /?(?!ouid)(.*)=(.*)920(.*)
没有运气。
When I use the rule /?s=(.*)920(.*)
, it will place /?/
in the middle of the url path. 当我使用规则
/?s=(.*)920(.*)
,它将/?/
放在url路径的中间。 For example domain.com/?/all-things-920/
例如
domain.com/?/all-things-920/
You can use a rewrite rule like this: 您可以使用如下重写规则:
RewriteCond %{QUERY_STRING} (?:^|&)s=.*?920[^&]*(?:&|$)
RewriteRule ^ /all-things-920/? [L,R]
如果您真的只想要正则表达式在/s=
上匹配任何920
字符串,则可以尝试:
/s=(.*)920(.*)
That redirection logic should belong in PHP, not in the .htaccess or whatever it is you are redirecting. 重定向逻辑应该属于PHP,而不是.htaccess或您正在重定向的任何东西。
Then you can easily check the $_GET['s']
value. 然后,您可以轻松检查
$_GET['s']
值。
You can redirect with header("Location: www.domain.com/wherever");
您可以使用
header("Location: www.domain.com/wherever");
进行重定向header("Location: www.domain.com/wherever");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.