【问题标题】:Redirect One Page to http instead of https将一页重定向到 http 而不是 https
【发布时间】:2019-06-24 11:49:07
【问题描述】:

我有如下所示的 .htaccess 文件,用于强制 https 访问我的所有页面。

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net
RewriteRule ^(.*)$ https://www.example.net/$1 [R,L]

根据我的要求,它工作正常。现在我想为我的一个名为 demo.html 的页面排除 https 我不想要https。 它的需要

http://example.net/demo.html 

而不是

https://example.net/demo.html

【问题讨论】:

  • 希望该页面重定向到 https,还是希望该页面重定向到 http 而所有其他页面都使用 https?

标签: php .htaccess ssl


【解决方案1】:

您需要为其添加RewriteCond 条件。

检查以下代码:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(www\.)?example\.net
RewriteCond %{REQUEST_URI} !^/demo\.html$ [NC]
RewriteRule ^(.*)$ https://www.example.net/$1 [R,L]

【讨论】:

    【解决方案2】:

    你可以像这样在相同数量的行中做到这一点:

    RewriteEngine On 
    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule !^demo\.html$  https://www.%1%{REQUEST_URI} [L,R]
    

    如果没问题,请将R 更改为R=301 以获得永久重定向,因为单独R 将被视为R=302 并且该临时重定向。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 2013-04-15
      • 2019-08-04
      • 1970-01-01
      相关资源
      最近更新 更多