2012-02-12 120 views
-1

我希望使用http来强制https的文件夹https_folder(包括所有子文件夹和文件),但是每个其他目录或文件都是如此。使用.htaccess限制https访问除1个文件夹外的所有内容

文件夹结构:

  1. foldera
  2. FolderB中
  3. https_folder
  4. folderc

我试图将其设置为跟随,但是我不似乎得到它的工作

重定向http/h ttps_folder

RewriteCond %{SERVER_PORT} = 80 
RewriteRule ^https_folder/?$ https://%{HTTP_HOST}%/httpd_folder [R=301,QSA,L,NE] 

重定向HTTPS非/市场页

RewriteCond %{SERVER_PORT} =443 
RewriteCond %{REQUEST_URI} !^/https_folder [NC] 
RewriteRule ^/?(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] 

任何帮助,将不胜感激

回答

0

这样做:

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

RewriteCond %{HTTPS} on 
RewriteCond %{REQUEST_URI} !/https_folder/? [NC] 
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L,NE] 
0

将这个代码在.htaccess文件:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 

# redirect to https if URI has https_folder 
RewriteCond %{HTTPS} off 
RewriteRule ^https_folder/? https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NC] 

# redirect to https if URI doesn't have https_folder 
RewriteCond %{HTTPS} on 
RewriteRule ^(?!https_folder/?)(.*)$ http://%{HTTP_HOST}/$1 [R=301,L,NC] 
相关问题