2012-03-18 95 views
0

我试图让浏览器重定向,只要用户在/index.php/index.php//index.php////中键入简单的/即可。这是我到目前为止php从/index.php重定向到/

if ($_SERVER['ORIG_PATH_INFO'] == '/index.php') { 
    header('HTTP/1.1 301 Moved Permanently'); 
    header('Location: http://'.$_SERVER['HTTP_HOST'].'/' 
} 

但是我得到一个无限循环重定向错误。我究竟做错了什么?有什么办法可以做到这一点?

编辑,似乎改变'ORIG_PATH_INFO''REQUEST_URI'做的伎俩/index.php我该怎么添加到我的if照顾index.php/index.php//// ...?

+0

您重定向的index.php到/这意味着同样的事情 – safarov 2012-03-18 12:50:01

+0

@safarov出现搜索index.php:是的,但它会在地址栏更好,并且出于航行原因我需要它。 – qwertymk 2012-03-18 12:52:12

+0

你也可以用.htaccess文件来做。如果你想我可以写U带htaccess的 – safarov 2012-03-18 12:56:15

回答

2

使用REQUEST_URI。当您使用ORIG_PATH_INFO时,您将永远得到/index.php

+0

我买了'REQUIEST_URI'了同样的问题这就是为什么我认为'ORIG_PATH_INFO'可能工作 – qwertymk 2012-03-18 12:51:00

+0

所以也许使用'mod_rewrite'? – 2012-03-18 12:55:31

+0

好吧,它似乎现在工作,有没有什么办法来检查index.php /和index.php //// ...? – qwertymk 2012-03-18 12:55:42

1

基础的条件上,而不是$_SERVER['REQUEST_URI']当URL实际上并不包含index.php它不会尝试和重定向。

,并使用stristr无论它在url

http://us3.php.net/manual/en/function.stristr.php

+0

好吧,它似乎现在工作,有没有什么办法来检查'index.php /'和'index.php ////'...? – qwertymk 2012-03-18 12:55:24

+0

我想为我推荐使用'stristr'检测含有的index.php或者说http://us3.php.net/manual/en/function.stristr.php – dldnh 2012-03-18 12:57:25

+0

是的,但它可能任何变化的任何网址包含在查询字符串 – qwertymk 2012-03-18 12:58:37