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?

  • 写回答

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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?