我的.htaccess
文件中包含以下行:
Redirect 301 /folder1 https://www.example.com/folder2/file.php
这会将所有内容从/folder1
重定向到https://www.example.com/folder2/file.php
。
我需要一个条件,仅在URL包含mykey=
GET参数时才允许此重定向,否则请忽略此重定向命令。
我该怎么做?
答案 0 :(得分:1)
您不能使用执行基本URI匹配的Redirect
指令来执行此操作。
您将需要使用基于mod_rewrite
的规则,例如:
RewriteEngine On
RewriteCond %{QUERY_STRING} (^|&)mykey= [NC]
RewriteRule ^folder1(/|$) /folder2/file.php [R=301,L,NC]
确保在测试之前清除缓存。
参考:
答案 1 :(得分:0)
我终于找到了可行的解决方案:
RewriteCond %{REQUEST_URI} ^/folder1/
RewriteCond %{QUERY_STRING} mykey=
RewriteRule ^folder1\/$ /folder2/file.php$1 [R=301,L]