.htaccess关闭特定目录的SSL

时间:2016-01-26 23:24:06

标签: php apache .htaccess ssl

我想为我网站的/ builder目录关闭SSL。 我尝试了很多不同的.htaccess配置,但要么我把它们放错了,要么就是不行。

这是我目前的.htaccess:

Options +Indexes
RewriteEngine on
Redirect 301 /index.html /index.php
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.cdghost.xyz/$1 [R,L]
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html 
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 503 /503.html
ErrorDocument 504 /504.html

谢谢!

1 个答案:

答案 0 :(得分:1)

试试这个

Options +Indexes
RewriteEngine on
Redirect 301 /index.html /index.php

RewriteCond %{SERVER_PORT} 80
RewriteRule ^((?!builder/).*)$ https://www.cdghost.xyz/$1 [R,L]
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html 
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 502 /502.html
ErrorDocument 503 /503.html
ErrorDocument 504 /504.html

您还可以使用RewriteCond从HTTPS重定向中排除/构建器:

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

RewriteCond检查以确保请求的uri不是 / builder /..// strong>,如果它不是/ builder ..,则请求被重定向到SSL。