【问题标题】:Prevent specific page from being redirected to https防止特定页面被重定向到 https
【发布时间】:2021-01-10 05:44:59
【问题描述】:

我需要避免将页面从我的网站重定向到 https,但我不想使用 php、java 或其他编程语言。

我想使用 .htaccess

在我的网站上,我使用 .htaccess 中的以下规则将网站上的所有页面重定向到 HTTPS。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

效果很好!

但是,我需要使用 HTTP 中的特定页面,因为它们通过 HTTP 中的 iframe 显示外部内容,而 HTTP 不显示在 HTTPS 中。

我试过了,把代码no_ssl加到url末尾

我在 htaccess 中添加了下面的摘录,这样 ssl 就不会应用于以 no_ssl

结尾的 url
RewriteCond ^(.*)$ ([^n]|n[^o]|no[^_]|no_[^s]|no_s[^s]|no_ss[^l])$ 

所以完整的代码如下所示:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond ^(.*)$ ([^n]|n[^o]|no[^_]|no_[^s]|no_s[^s]|no_ss[^l])$ 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

所以我希望页面 mydomain.com/contact-no_ssl 不会被重定向到 https。但它不起作用。

我也测试了代码:

RewriteCond %{REQUEST_URI} !^(.*)no_ssl$

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/contact-no_ssl.* [NC] 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

但是,注意工作。

我得到的最大值是被重定向到主页。

有人可以帮我吗?

【问题讨论】:

标签: apache .htaccess redirect https


【解决方案1】:

你可以试试这个规则:

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !no_ssl[\s?] [NC] 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

使用THE_REQUEST 而不是REQUEST_URI,因为在应用其他规则后THE_REQUEST 不会针对单个请求进行更新。

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 2014-03-10
    • 2011-10-06
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 2012-03-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多