dsmvovm27249
2016-05-13 05:15
浏览 30
已采纳

为什么我的Php脚本用/重定向用户?

I have a script running on my site which is meant to redirect users who browser to '/' and then send them to 'www.' using a 302 redirect.

What I am confused about in Chrome is why it works but ends up sending them to...

http://www.example.com//

I downloaded the script and don't really understand it.... Basically I want the script to take anybody who is going to /site.com and redirect them using 302 to www.site.com

This is the script..

<?php

$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";

if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
    header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']);
    exit;
}

include_once("index/index.html");

?>

Any ideas?

图片转代码服务由CSDN问答提供 功能建议

我的网站上运行了一个脚本,用于将浏览器的用户重定向到“/”然后发送给他们 到'www。' 使用302重定向。

在Chrome中我感到困惑的是它的工作原理,但最终将它们发送给...

http://www.example.com//

我下载了脚本 并且我真的不明白....基本上我希望脚本能够带任何人去/site.com并使用302将它们重定向到www.site.com

这个 是脚本..

 &lt;?php 
 
 $ protocol =(@ $ _ SERVER [“HTTPS”] ==“on”)?  “https://”:“http://”; 
 
if(substr($ _ SERVER ['HTTP_HOST'],0,4)!=='www。'){
 header('Location:'  。$ protocol.'www。'。$ _ SERVER ['HTTP_HOST']。'/'。$ _ SERVER ['REQUEST_URI']); 
退出; 
} 
 
include_once(“index / index.html”)  ; 
 
?&gt; 
   
 
 

任何想法?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douben1891 2016-05-13 05:29
    最佳回答

    Change your Code from

    header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].'/'.$_SERVER['REQUEST_URI']);

    to

    header('Location: '.$protocol.'www.'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

    As, you are adding an extra forward slash.

    Hope, it helps.

    评论
    解决 无用
    打赏 举报