【问题标题】:.htaccess redirect 2 http pages to https pages.htaccess 将 2 个 http 页面重定向到 https 页面
【发布时间】:2013-03-27 14:33:11
【问题描述】:

我在重定向 2 个简单的 html 页面时遇到了一些麻烦。

我需要设置重定向:

  1. http://example.com/Folder1/page1.html 到https://example.com/Folder1/page1.html
  2. http://example.com/Folder1/Folder2/page2.html https://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 redirect


    【解决方案1】:
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^(/Folder1/(page1\.html|Folder2/page2\.html))$ [NC]
    rewriterule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 
    

    【讨论】:

    • 这个规则是不是必须放在站点根目录下的.htaccess中?或在文件夹 1 .htaccess 中?
    • 我尝试将此规则添加到根目录的 .htaccess 文件中,并且仅适用于 Folder2。可能是 Folder2 是 Folder1 的子文件夹的问题?
    • 最好将它们放在站点根目录的 .htaccess 中,重定向工作正常(我已经在 htaccess.madewithlove.be 上测试过),您是否尝试将 Folder2 下的所有 html 页面重定向到 https ?
    猜你喜欢
    • 2013-10-18
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 2018-02-03
    • 2021-06-13
    • 2015-06-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多