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将2个http页面重定向到https页面_.htaccess_Redirect - Fatal编程技术网

.htaccess将2个http页面重定向到https页面

.htaccess将2个http页面重定向到https页面,.htaccess,redirect,.htaccess,Redirect,我在重定向2个简单的html页面时遇到了一些问题 我需要为以下内容设置重定向: http://example.com/Folder1/page1.html至 http://example.com/Folder1/Folder2/page2.html 只有这两个页面必须从http重定向到https。任何其他页面必须可用于http和https 我尝试了以下规则: RewriteCond %{SERVER_PORT} !=443 rewriterule ^(Folder1)$ https://%{H

我在重定向2个简单的html页面时遇到了一些问题

我需要为以下内容设置重定向:

  • http://example.com/Folder1/page1.html至
  • http://example.com/Folder1/Folder2/page2.html
  • 只有这两个页面必须从http重定向到https。任何其他页面必须可用于http和https

    我尝试了以下规则:

    RewriteCond %{SERVER_PORT} !=443 
    rewriterule ^(Folder1)$ https://%{HTTP_HOST}/$1 [R=301,L] 
    RewriteCond %{SERVER_PORT} 1=443 
    RewriteCond $1 ^Folder1/Folder2 
    rewriterule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 
    
    但只有第二个重定向有效。第一个仍然打开http页面


    有人能帮我写正确的规则吗?

    这些规则必须放在网站根目录的.htaccess中吗?或者在folder1.htaccess中?我尝试将此规则添加到根目录.htaccess文件中,并且仅适用于Folder2。可能是Folder2是Folder1的子文件夹的问题?最好将它们放在站点根目录中的.htaccess中,重定向工作正常(我已经对其进行了测试),是否尝试将Folder2下的所有html页面重定向到https?
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^(/Folder1/(page1\.html|Folder2/page2\.html))$ [NC]
    rewriterule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]