【问题标题】:htaccess redirect to https exclude one urlhtaccess 重定向到 https 排除一个 url
【发布时间】:2018-10-08 13:54:58
【问题描述】:

我知道它的重复,并且在谷歌中有很多答案,但对我来说没有任何用处。
我对 apache 的要求不高,甚至不平均,但我想从 HTTPS 重定向中排除一个以 /test/ 开头的网址。

//redirect not working
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^\/(/test/)
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

RewriteCond %{HTTP:X-Forwarded-Proto} https
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^\/(/test/)
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

//infinity loop
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{REQUEST_URI} ^\/(test)
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]

RewriteCond %{HTTP:X-Forwarded-SSL} =on
RewriteCond %{REQUEST_URI} !^\/test)
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]

//thats my first HTTPS redirect, tried to add RewriteCond to exclude test, but nothing works
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/test/ [NC] 
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

感谢您的帮助。

【问题讨论】:

    标签: apache .htaccess http https


    【解决方案1】:

    自己找到答案

        # force https:// for all except some selected URLs    
        RewriteCond %{HTTPS} off
        RewriteCond %{THE_REQUEST} !/test/ [NC]
        RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
        # force http:// for selected URLs
        RewriteCond %{HTTPS} on
        RewriteCond %{THE_REQUEST} /test/ [NC]
        RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 2014-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-06
      • 2016-02-25
      • 2015-12-04
      • 1970-01-01
      相关资源
      最近更新 更多