【问题标题】:redirect http to https via htaccess only for few pages仅针对少数页面通过 htaccess 将 http 重定向到 https
【发布时间】:2011-03-28 07:39:27
【问题描述】:

我有启用 SSL 的网站。

问题:我希望 http 仅针对结帐页面重定向到 https。

我正在使用以下代码进行重定向:

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

但它会将所有 http 重定向到 htaccess。

我想要什么:我想对 htaceess 设置一些条件,以便只有结帐页面会重定向到 https,否则不会进行重定向。

【问题讨论】:

    标签: .htaccess https


    【解决方案1】:

    您必须捕获来自端口 80 的结帐页面的请求

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80 
    RewriteCond %{REQUEST_URI} your-checkout-uri-pattern
    RewriteRule ^(.*)$ https://your-sslized-site/$1 [R,L]
    

    【讨论】:

      【解决方案2】:

      下面的代码解决了我的问题(当我在 api 中使用它时)。它也可能解决您的问题。试试看吧。

      给你,

      # For redirecting HTTP to HTTPS, comments are line by line
      # below line checks for https flag
      RewriteCond %{HTTPS} off
      # below line excludes the mentioned URIs from redirection
      RewriteCond %{REQUEST_URI} !^/(myFirstUri|mySecondUri|myThirdUri)
      # below line redirects all other URIs except the ones that are mentioned above
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
      

      所以,这里发生的事情是我所有的请求都将被重定向到 https,除了下面的请求

      abc.123/myFirstUri 将变为http://abc.123/myFirstUri

      abc.123/myFirstUri/qw/etc 也将如上所述重定向

      其他请求将被重定向到 https,例如

      abc.123/test 变为https://abc.123/test

      【讨论】:

        猜你喜欢
        • 2012-11-07
        • 1970-01-01
        • 1970-01-01
        • 2013-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-29
        相关资源
        最近更新 更多