大网数据广告活动
网站运营与故障问答

htaccess - RewriteCond is met, but RewriteRule doesn't run

· 52CE 我爱测

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? …

问题原文

原帖链接 · 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)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2021-08-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。