【问题标题】:PHP script that forwards by reading the subdomain WHILE using https通过使用 https 读取子域 WHILE 进行转发的 PHP 脚本
【发布时间】:2018-11-03 04:45:39
【问题描述】:

我有一个 php 脚本,它根据 url 中写入的子域转发用户。

现在,通常您会读取 HTTP_URI,但我的虚拟主机使用 iframe,所以我必须读取 HTTP_REFERRER。

现在问题来了,当访问“正常”站点时,例如 mysite.com 或

http://example.com

它工作正常,但是,当使用 https 时,它只显示一个白页。

这是我的代码:

<?PHP

$REFERRER = $_SERVER['HTTP_REFERER'];

// Or other method to get a URL for decomposition 
$domain = substr($REFERRER, strpos($REFERRER, '://')+3); 
$domain = substr($domain, 0, strpos($domain, '/')); 
// This line will return 'en' of 'en.example.com' 
$subdomain = substr($domain, 0, strpos($domain, '.')); 
//Echo $subdomain;

header("Location: https://example2.com/'$subdomain");
?>

.. 有人有什么建议吗? 重写不适用于此服务器上的子域。

【问题讨论】:

  • 您可能会发现使用parse_url() 函数更容易。
  • 我花了两周时间才得到这个(大部分)有效的
  • “但是我的虚拟主机正在使用 iframe” - 请正确解释这实际上是什么意思。 “它工作正常,” - 不,它没有,很多客户不发送推荐人。 “但是,当使用 https 时,它只显示一个白页” - 可能是由于引荐来源政策,请检查是否设置了类似的内容。
  • 那是糟糕的托管...我首先会切换到提供适当设置的托管。
  • 您在使用 https 时是否有混合内容?你能检查一下控制台吗?

标签: php subdomain forward wildcard-subdomain


【解决方案1】:

正如 cmets 中所讨论的,问题是“阻止加载混合活动内容”。

如果包含 iframe 的网站是通过 https 加载的,则无法通过 http 加载 iframe 或其内容。

【讨论】:

    【解决方案2】:

    在你的 .htaccess 中使用它来重写 https

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

    您可以将其用于子域

    RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ [NC]
    RewriteRule ^((?!sub1/).*)$ /$1 [L,NC]
    

    解释here

    【讨论】:

      猜你喜欢
      • 2017-12-30
      • 1970-01-01
      • 2021-08-12
      • 2011-12-04
      • 2011-05-29
      • 1970-01-01
      • 2015-10-24
      • 2013-07-28
      相关资源
      最近更新 更多