除一个特定请求外,.htaccess重定向

时间:2017-02-11 14:09:45

标签: .htaccess redirect

我有一个.htaccess文件,见下文

Options +FollowSymLinks +ExecCGI

<IfModule mod_rewrite.c>

#Every www request to non-www
RewriteEngine On    
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]

#every http request in amdinistrator folder redirect to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/administrator
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

#every https request except ftp and one specific request redirect to http
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/ftp
RewriteCond %{REQUEST_URI} !=/preview/index.php?request_type=preview_engime
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]

#redirect which request contains PUBLIC_AJAX_ENGIME
RewriteRule ^(.*)PUBLIC_AJAX_ENGIME(.*)$ index.php?request_type=ajax_engime [L]

#files and directories
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

</IfModule>

在这种情况下我不想重定向:

https://somewebsite.domain/preview/index.php?request_type=preview_engime

但系统重定向到这里

http://somewebsite.domain/index.php?request_type=preview_engime

我不明白为什么。

谢谢! FF

1 个答案:

答案 0 :(得分:0)

这是因为您的网址包含查询字符串。您无法使用REQUEST_URI变量与QueryString匹配。您需要匹配THE_REQUEST变量。用这个替换你的RewriteCond:

RewriteCond %{THE_REQUEST} !/index\.php\?request_type=preview_engime [NC]