问题原文
原帖链接 · Adriano · CC BY-SA 4.0
I am trying to match both a filename and querystring in my .htaccess file. When using an online testing tool (this one), it tells me that the conditions are being met, but the following rule doesn't run. What am I doing wrong?
Here's the mod_rewrite part of my .htaccess file:
RewriteCond %{REQUEST_URI} ^/omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba.php [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?cat=1(&.*)pr=4$ [NC,OR]
RewriteCond %{QUERY_STRING} ^(.*&)?cat=1(&.*)pr=1$ [NC]
RewriteRule https://www.example.com/bagno-seta-mandorla/ [QSD,R=301,L]
And here's the URL it's supposed to redirect:
http://www.example.com/omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba.php?cat=1&pr=1
已采纳解答
原帖链接 · julp · CC BY-SA 4.0
A pattern and argument is missing to your RewriteRule line.
You also probably can simplify this rule like the following:
# if the path is "/omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba.php"
# and the query string contains a cat parameter valued to "1"
RewriteCond %{QUERY_STRING} (?:^|&)cat=1(?:&|$)
# and the query string also contains a pr parameter valued to "1" or "4"
RewriteCond %{QUERY_STRING} (?:^|&)pr=[14](?:&|$)
# then redirect permanently to https://www.example.com/bagno-seta-mandorla/ (without keeping the old query string by the QSD option)
RewriteRule ^omialab/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba/omia-linea-erboristica-prodotti-erboristici-per-il-corpo-olio-di-mandorla-argan-jojoba\.php$ https://www.example.com/bagno-seta-mandorla/ [QSD,R=permanent,NC,L]
(supposing the .htaccess is in / directory)
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
