简体   繁体   English

单页301重定向HTTPS到HTTP

[英]301 redirect HTTPS to HTTP for a single page

I currently have a SSL certificate applied to my site and ALL URLs redirect to https correctly.我目前有一个 SSL 证书应用于我的网站,所有 URL 都正确重定向到 https。 I need one of the URLS to be HTTP.我需要其中一个 URL 为 HTTP。 I have the following code in my .htaccess that redirects all pages to HTTPS.我的 .htaccess 中有以下代码,它将所有页面重定向到 HTTPS。

I would like the following URL below to be HTTP and NOT HTTPS.我希望下面的 URL 是 HTTP 而不是 HTTPS。

http://www.example.com/blog_rss.php

RewriteEngine on
RewriteBase /
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Thanks in advance for your assistance提前感谢你的帮助

You can replace your current code by this one in your htaccess 您可以在htaccess中用此代码替换当前代码

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{HTTPS} on
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

EDIT: looks like %{HTTPS} is not recognized on some servers, which is causing an infinite loop. 编辑:在某些服务器上无法识别%{HTTPS} ,这将导致无限循环。

Try with %{SERVER_PORT} (if default http port is still 80 and ssl port is 443) 尝试使用%{SERVER_PORT} (如果默认的http端口仍然是80,而ssl端口是443)

RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{SERVER_PORT} 443
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

You could also try with your initial syntax 您也可以尝试使用初始语法

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{REQUEST_URI} !^/blog_rss\.php$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L,QSA]

RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule ^(blog_rss\.php)$ http://%{HTTP_HOST}/$1 [R=301,L,QSA]

I got similar issue, I have a SSL certificate applied to my sub domain(abc.example.in) and ALL URLs redirect to https correctly.我遇到了类似的问题,我有一个 SSL 证书应用于我的子域(abc.example.in),并且所有 URL 都正确重定向到 https。

I need one of the page to be HTTP.我需要其中一页是 HTTP。 I have the following code in my .htaccess that redirects all pages to HTTPS.我的 .htaccess 中有以下代码,它将所有页面重定向到 HTTPS。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^abc\.example\.in$
RewriteCond %{REQUEST_URI} !^/driving\.php$
RewriteRule .* https://abc\.example\.in%{REQUEST_URI} [R=301,L]

It still redirects to https, when i hit URL(abc.example.in/driving.php) in browser, please suggest.当我在浏览器中点击 URL(abc.example.in/driving.php) 时,它仍然重定向到 https,请建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM