【问题标题】:Redirect select pages to https将选择页面重定向到 https
【发布时间】:2013-04-10 21:14:11
【问题描述】:

我有一个非常简单的问题,由于某种原因我无法弄清楚,而且数小时的搜索也没有帮助。使用 .htaccess 文件,我如何将 /login.php/index.php 重定向到 https,然后将任何其他页面重定向到 http?我目前使用此代码重定向到 https,但它会重定向每个页面:

RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*) https://www.ruxim.com/$1 [R]  

非常感谢。

【问题讨论】:

    标签: .htaccess mod-rewrite ssl


    【解决方案1】:

    %{SERVER_PORT} 变量取决于配置中的 UseCanonicalPhysicalPort。如果没有设置,那么您可能无法匹配该变量,更容易使用%{HTTPS}

    RewriteCond %{HTTPS} off
    RewriteRule ^/?(login|index)\.php https://www.ruxim.com%{REQUEST_URI} [L,R]
    
    RewriteCond %{HTTPS} on
    RewriteRule !^/?(login|index)\.php http://www.ruxim.com%{REQUEST_URI} [L,R]
    

    如果您不需要重定向到非 https,则不需要第二条规则。

    【讨论】:

      【解决方案2】:

      试试这样的;

      RewriteCond %{SERVER_PORT} !^443$
      RewriteCond %{REQUEST_FILENAME} =index.php [OR]
      RewriteCond %{REQUEST_FILENAME} =login.php
      RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
      

      我注意到 100% 确定 [OR] 是否会在中间突然遵守。

      【讨论】:

        【解决方案3】:

        请应用以下条件以仅保护 /login.php 和 /index.php 页面。其他页面将在 HTTP 路径上工作(非安全页面)。

        RewriteEngine On
        RewriteBase /
        # force https for /login.php and /index.php
        RewriteCond %{HTTPS} =off
        RewriteRule ^(index|login)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
        
        # don't do anything for images/css/js (leave protocol as is)
        RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
        
        # force http for all other URLs
        RewriteCond %{HTTPS} =on
        RewriteCond %{REQUEST_URI} !^/(index|login)\.php$
        RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
        

        【讨论】:

          猜你喜欢
          • 2018-08-31
          • 1970-01-01
          • 1970-01-01
          • 2011-12-07
          • 2011-05-01
          • 2016-11-18
          • 1970-01-01
          • 2011-10-06
          • 2013-10-18
          相关资源
          最近更新 更多