dsmvovm27249 2016-05-12 21: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?

  • 写回答

1条回答 默认 最新

  • douben1891 2016-05-12 21: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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?