When I search for " abc 920 def" on my site, the domain fires:
http://www.domain.com/?s=abc+920+def
Then, this redirection rule:
/?(.*)=(.*)920(.*)
will redirect it to a category: 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.
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?
I tried: /?(?!ouid)(.*)=(.*)920(.*)
without luck.
When I use the rule /?s=(.*)920(.*)
, it will place /?/
in the middle of the url path. For example 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.
Then you can easily check the $_GET['s']
value.
You can redirect with header("Location: www.domain.com/wherever");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.