Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用.htaccess限制https访问除1个文件夹外的所有内容_.htaccess_Mod Rewrite - Fatal编程技术网

使用.htaccess限制https访问除1个文件夹外的所有内容

使用.htaccess限制https访问除1个文件夹外的所有内容,.htaccess,mod-rewrite,.htaccess,Mod Rewrite,我想让文件夹https_文件夹(包括所有子文件夹和文件)强制使用https,但每个其他目录或文件都使用http 文件夹结构: 福尔德拉 folderb https\u文件夹 folderc 我试着设置如下,但我似乎没有得到它的工作 http/https\u文件夹的重定向 RewriteCond %{SERVER_PORT} = 80 RewriteRule ^https_folder/?$ https://%{HTTP_HOST}%/httpd_folder [R=301,QSA,L,NE]

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

文件夹结构:

  • 福尔德拉
  • folderb
  • https\u文件夹
  • folderc
  • 我试着设置如下,但我似乎没有得到它的工作

    http/https\u文件夹的重定向

    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]
    
    如有任何帮助,将不胜感激。请执行以下操作:

    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]
    

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