强制HTTPS除特定目录外

时间:2011-08-16 03:06:00

标签: .htaccess mod-rewrite

我正在使用以下.htaccess文件强制将任何页面请求发送到https://

RewriteEngine On
RewriteBase /

#Force SSL
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

如何修改此脚本以继续强制https://除了http://example.com/api/(“api”文件夹)等指定目录外?

1 个答案:

答案 0 :(得分:1)

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/yournonhttpsdirectory/
RewriteRule ^(.*)$ https://www.domain.xyz/$1 [R,L]

也许这可能有效?