【问题标题】:Htaccess HTTPS redirectionHtaccess HTTPS 重定向
【发布时间】:2011-07-04 21:16:50
【问题描述】:

我正在尝试让我的 .htaccess 文件仅将某些页面/文件夹重定向到 https,如果它不是需要加密的页面,那么它应该向用户发送 http 页面。此外,我希望能够列出可以是 HTTP 或 HTTPS 的某些文件夹

这是我自己尝试使用的。但似乎无法正常工作。

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond $1 ^(myaccount|payment\.html)
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond $1 !^(myaccount|payment\.html)
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
</IfModule>

【问题讨论】:

    标签: php apache .htaccess mod-rewrite redirect


    【解决方案1】:

    您正在检查 RewriteCond 模式中的文字 $1。应该是:

    RewriteCond %{REQUEST_URI} ...stuff to match against here...
    

    【讨论】:

      【解决方案2】:

      这应该做你想做的。

      RewriteCond %{SERVER_PORT} 443 [NC]
      RewriteCond %{REQUEST_URI} !^/(myaccount|payment)\.html [NC]
      RewriteRule . http://www.domain.com/%{REQUEST_URI}/ [R=301,L]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-03-05
        • 2017-07-15
        • 1970-01-01
        • 2022-01-11
        • 2021-11-10
        • 2012-12-23
        • 2020-07-11
        相关资源
        最近更新 更多