区分Apache中的HTTP和HTTPS请求

时间:2014-02-20 13:56:33

标签: apache

对于特定文件,我需要重定向,具体取决于它是HTTP还是HTTPS以及HTTP方法GET。几乎没有问题。

我正在使用setenvif来了解传入的请求是HTTP还是HTTPS

SetEnvIfNoCase Proxied-SSL。是。 IS_HTTPS

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

提前致谢

1 个答案:

答案 0 :(得分:0)

要检查请求是来自 http 还是 https ,您可以使用RewriteCond%{HTTPS}

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

更新:由于您要求使用环境品种,这是您的解决方案:

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]