htaccess RewriteCond和RewriteRule不是HTTPS

时间:2017-02-23 14:53:44

标签: .htaccess mod-rewrite

我的htaccess文件中有几个规则。 在任何情况下,使用一个块我将行为更改为HTTPS,下一个块我将定义一个异常

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule (.*) https://%{HTTP_HOST}/$1 [L] 

  # but not SOAP or APP-calls # 
  RewriteCond %{SERVER_PORT} ^443$
  RewriteCond %{QUERY_STRING} ^type=8800882$
  RewriteCond %{QUERY_STRING} (.*(?:^|&))action=.*
  RewriteRule (.*) http://%{HTTP_HOST}/$1 [L] 
</IfModule>

第一个块完成它的工作。 但是,使用参数&#34; type = 8800882&#34;强制HTTP是不可能的。或者在请求中添加参数操作。

这是我的第二次尝试,首先我做了这个(工作,但现在已经破了):

<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      # all should be HTTPS #
      RewriteCond %{SERVER_PORT} !^443$
      RewriteCond %{QUERY_STRING} !^type=8800882$
      RewriteCond %{QUERY_STRING} !(.*(?:^|&))action=.*
      RewriteRule (.*) https://%{HTTP_HOST}/$1 [L]
    </IfModule>

如果参数类型= 8800882或参数action = *?

,如何为非HTTPS设置例外?

1 个答案:

答案 0 :(得分:0)

您可以使用以下规则:

RewriteEngine on


#exclude /?action=.* and ?type=8800882
RewriteCond %{THE_REQUEST} !\?(?:type=8800882|action=.*) [NC]
 #http to https
RewriteCond %{SERVER_PORT} !443
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NE,L,R]
相关问题