douan6931
2018-05-24 04:46 阅读 73
已采纳

通过使用https读取子域WHILE进行转发的PHP脚本

I've got a php script that forwards the user based on what subdomain the wrote in the url.

Now, normally you would read the HTTP_URI, but my webhost are using iframe, so I have to read the HTTP_REFERRER.

now to the problem, when accessing the site "normal", like mysite.com or

http://example.com

it works fine, however, when using https, it only shows a white page.

This is my code:

<?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");
?>

.. Anybody got any suggestions? Rewriting doesn't work on subdomains on this server.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dphe5602 dphe5602 2018-05-24 08:52

    As discussed in the comments the problem is "blocked loading mixed active content".

    An iframe or its contents can not be loaded over http if the site containing the iframe is loaded via https.

    点赞 评论 复制链接分享
  • douzhuican0041 douzhuican0041 2018-05-24 07:18

    use this for your https rewrite in your .htaccess

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

    and you can use this for the subdomain

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

    Explanation here

    点赞 评论 复制链接分享

相关推荐