【问题标题】:Force http on two pages using the .htaccess使用 .htaccess 在两个页面上强制 http
【发布时间】:2019-10-01 17:09:42
【问题描述】:

我想使用 .htaccess 文件将页面从 HTTPS 重定向到 HTTP。

我已经为一个页面添加了代码,但是当我为 page2 添加它时,它会给站点一个重定向错误。

这是我的代码,适用于 .htaccess 中从 HTTPS 到 HTTP 的一页,我还确保 .htaccess 位于该目录中,其中包含我想要重定向的文件。

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]


RewriteCond %{SERVER_PORT} !80

RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]

RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]

但是当我像下面这样添加它时它不起作用并且我收到重定向错误。

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]

RewriteCond %{REQUEST_URI} !^/page2.php$ [NC]

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]


RewriteCond %{SERVER_PORT} !80

RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]

RewriteCond %{REQUEST_URI} ^/page2.php$ [NC]

RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]

我希望页面仅使用 .htaccess 文件转到 HTTP 而不会出错:

http://mywebsite.com/page1.phphttp://mywebsite.com/page2.php

【问题讨论】:

    标签: .htaccess http ssl https


    【解决方案1】:

    我想通了。我需要的正确代码如下:

    RewriteCond %{SERVER_PORT} 80

    RewriteCond %{REQUEST_URI} !^/(page2.php$|page1.php$) [NC]

    重写规则 ^(.*)$ https://www.mywebsite.com/$1 [R,L]

    RewriteCond %{SERVER_PORT} !80

    RewriteCond %{REQUEST_URI} ^/(page2.php$|page1.php$) [NC]

    重写规则 ^(.*)$ http://mywebsite.com/$1 [R,L]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      • 2017-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-28
      • 1970-01-01
      相关资源
      最近更新 更多