将http重定向到https排除特定网址

时间:2017-11-20 12:45:23

标签: apache .htaccess redirect mod-rewrite

This问号已解决(解决方案确实有效!),但我不这么认为 在我的情况下,/api/.*应该是http
像这样的规则

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/api.*$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
如果从/api

开始,

将会重定向并丢失请求URI

UPD:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (^/(?!api).*$) [NC]
RewriteRule ^ https://%{HTTP_HOST}%1 [L,R=301,QSA]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (^/(?!api).*$) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]

给出相同的结果= \
感觉像RewriteCond,排除表达式返回true,但是如果 %{REQUEST_URI}不匹配,然后将被清除。

同时

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/$ [OR]
RewriteCond %{REQUEST_URI} ^/foo [OR]
... all pages that you have ...
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

工作正常

0 个答案:

没有答案