简体   繁体   English

从安全https重定向到仅一页的http

[英]Redirect from secure https to http for only one page

I have a page, page.php that I need to be redirected to http if it is accessed through https because otherwise my google ads won't show up. 我有一个页面, page.php ,如果通过https访问我需要重定向到http ,否则我的谷歌广告将不会显示。

To be precise, I would like the following to happen: 确切地说,我希望发生以下情况:

https://site.com/page.php?blah=foo?bar=blah --> http://site.com/page.php?blah=foo?bar=blah https://site.com/page.php?blah=foo?bar=blah - > http://site.com/page.php?blah=foo?bar=blah

I have so far tried : 我到目前为止尝试过:

RewriteCond %{HTTP_HOST} on

RewriteRule ^page\\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But this doesn't work. 但这不起作用。 Any suggestions? 有什么建议么?

This might also be a quick copy paste 这也可能是一个快速复制粘贴

if ($_SERVER['HTTPS'] == "on") {
    $url = "http://". $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $url");
    exit;
} 
if($_SERVER['SERVER_PORT'] == '443')
{
   header('location:http://url.com');
}

if the secure port is set to other than 443 this will not work so you can also use 如果安全端口设置为443以外,则无法使用,因此您也可以使用

$_SERVER['HTTPS'] == 'on'

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

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