我想将所有页面请求重定向到另一个域,但是排除了一些我想要单独重定向的请求URI。所以我尝试过这样的事情:
RewriteCond %{REQUEST_URI} !^/index.php?id=132$ [NC,OR]
RewriteCond %{REQUEST_URI} !^/index.php?id=133$ [NC]
RewriteRule .* https://new-domain.com/? [R=301,L]
Redirect 301 /index.php?id=132 https://new-domain.com/example
Redirect 301 /index.php?id=133 https://new-domain.com/example2
但这不起作用,有人可以告诉我出了什么问题吗?
答案 0 :(得分:1)
%{REQUEST_URI}
变量或Redirect
指令与查询字符串不匹配。
你可以像这样使用更好的正则表达式:
RewriteCond %{THE_REQUEST} !/index\.php\?id=13[23][&\s] [NC]
RewriteRule ^ https://new-domain.com/? [R=301,L]
RewriteCond %{THE_REQUEST} /index\.php\?id=132[&\s] [NC]
RewriteRule ^ https://new-domain.com/example? [L,R=301]
RewriteCond %{THE_REQUEST} /index\.php\?id=133[&\s] [NC]
RewriteRule ^ https://new-domain.com/example2? [L,R=301]
另请注意,在目标网址中使用?
可放弃以前的查询字符串。