2014-02-20 62 views
-1

对于需要重定向的特定文件,具体取决于它是HTTP还是HTTPS和HTTP方法GET。有像几个问题。区分Apache中的HTTP和HTTPS请求

我使用SetEnvIf之后结识如果传入的请求是HTTP或HTTPS

SetEnvIfNoCase代理的SSL。 是的。 IS_HTTPS

如何在RewriteCond中使用这个变量IS_HTTPS?并提供以下重写/重定向指令将其重定向到HTTPS。

在此先感谢

回答

0

要检查请求是否来自HTTPHTTPS可以使用RewriteCond%{HTTPS}

RewriteCond %{HTTPS} on 
RewriteRule ^particular.php$ /https.php [L,R=302] 
RewriteCond %{HTTPS} off 
RewriteRule ^particular.php$ /http.php [L,R=302] 

更新:既然你问了使用环境的品种,这里的youre solution:

RewriteCond %{IS_HTTPS} yes 
RewriteRule ^particular.php$ https://%{HTTP_HOST}/https.php [L,R=302] 
RewriteCond %{IS_HTTPS} no 
RewriteRule ^particular.php$ http://%{HTTP_HOST}/http.php [L,R=302] 
+0

我想使用环境变量。那可能吗 ? – LinuxLearner

+0

我想使用环境变量。那可能吗 ?当我在RewriteRule ^(*)/ Mypage.xml上使用RewriteCond%{HTTPS}时 - 即使请求用于HTTPS,[F]也显示禁止。你可以让我知道更多的特殊情况吗?此外,请您在答案中解释RewriteRule。 – LinuxLearner

+0

当然你可以,我会编辑我的答案! – undone