【问题标题】:restrict https access with .htaccess to everything but 1 folder使用 .htaccess 将 https 访问限制为除 1 个文件夹之外的所有内容
【发布时间】:2012-02-13 02:26:49
【问题描述】:

我希望文件夹 https_folder(包括所有子文件夹和文件)强制使用 https,但每个其他目录或文件都使用 http。

文件夹结构:

  1. 文件夹
  2. 文件夹b
  3. https_文件夹
  4. 文件夹c

我尝试将其设置为如下,但我似乎无法正常工作

重定向 http /https_folder

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

重定向 https 非 /market 页面

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

任何帮助将不胜感激

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    这样做:

    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]
    

    【讨论】:

      【解决方案2】:

      将此代码放入您的 .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]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-01-08
        • 2014-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-25
        • 2011-11-11
        相关资源
        最近更新 更多