使用例外将http重定向到https

时间:2017-06-13 17:05:25

标签: php apache .htaccess ssl redirect

我有一个网站(比如说website.com),并使用.htaccess,内容如下:

ErrorDocument 403 /index.php
Options -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我需要将http重定向到https。为此,我在虚拟主机设置中添加了这一行:

Redirect permanent / https://website.com/

因此,它会将所有流量重定向到https

我的问题是我需要为我的重定向添加例外 对于前者此路由http://website.com/folder/test/ *之后的所有流量都应路由到HTTP

请帮忙 感谢

1 个答案:

答案 0 :(得分:0)

RewriteCond 在这种情况下有所帮助

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


# force http:// for selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /subfolder/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]