【问题标题】:https to http in .htaccess with exceptions.htaccess 中的 https 到 http 有例外
【发布时间】:2011-07-21 13:14:52
【问题描述】:

我已经做了足够多的研究,发现要将全站范围内的所有 https 页面重定向到相应的 http 页面,我需要使用此代码...

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

我的问题是,有一些页面我仍然想保留为 https。举例来说,假设我希望 page1.php、page2.php 和 page3.php 保留为 .https,并重定向站点上的所有其他内容。有人知道怎么做吗?

【问题讨论】:

    标签: linux http .htaccess redirect https


    【解决方案1】:

    试试这样的:

    RewriteEngine On
    
    # Force page1,2,3.php onto HTTPS
    RewriteCond %{HTTPS} off
    RewriteRule ^(page1|page2|page3)\.php https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA]
    
    # Redirect other HTTPS requests to plain HTTP
    RewriteCond %{HTTPS} on
    RewriteCond ${REQUEST_URI} !(page1|page2|page3)\.php
    RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,QSA] 
    

    【讨论】:

    • 对不起,我完全是新手。这会取代我的 3 条重定向规则吗?一切都必须按特殊顺序进行吗?您可以创建一个完整的 .htaccess 来总结所有内容吗?提前致谢!
    • 认为以上内容已经是正确顺序的完整 .htaccess。顶部块用一个正则表达式替换了您的三个谨慎规则。我还在重定向标志中添加了QSA 以传递任何查询字符串。
    • 这似乎导致page1、page2和page3无限循环。
    • https是开还是关时的循环?注释掉一个或另一个以缩小范围。或者在顶部尝试将RewriteCond %{HTTPS} off 更改为RewriteCond %{SERVER_PORT} !443
    猜你喜欢
    • 2013-04-25
    • 1970-01-01
    • 2010-12-21
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2016-03-10
    • 2015-03-19
    相关资源
    最近更新 更多