2017-06-13 89 views
1

我有一个网站(可以说website.com),使用的.htaccess,内容如下:重定向HTTP到HTTPS例外

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

请帮 感谢

+0

具有#2类似的问题。 [请参阅此链接](https://stackoverflow.com/questions/26426893/htaccess-redirect-to-https-except-a-few-urls) –

+1

可能重复[从https重定向到http,除了某些URI ](https://stackoverflow.com/questions/16065065/redirecting-from-https-to-http-with-the-exception-of-some-uris) –

回答

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]