Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php从/index.php重定向到/_Php_Apache_Redirect - Fatal编程技术网

php从/index.php重定向到/

php从/index.php重定向到/,php,apache,redirect,Php,Apache,Redirect,我试图让浏览器在用户键入/index.php或/index.php/或/index.php//时重定向到纯/。这是我到目前为止所拥有的 if ($_SERVER['ORIG_PATH_INFO'] == '/index.php') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://'.$_SERVER['HTTP_HOST'].'/' } 但我得到一个无限循环重定向错误。我做错了什么?有什么

我试图让浏览器在用户键入
/index.php
/index.php/
/index.php//
时重定向到纯
/
。这是我到目前为止所拥有的

if ($_SERVER['ORIG_PATH_INFO'] == '/index.php') {
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://'.$_SERVER['HTTP_HOST'].'/'
}
但我得到一个无限循环重定向错误。我做错了什么?有什么办法可以让这一切顺利进行吗


编辑,似乎将
'ORIG\u PATH\u INFO'
更改为
'REQUEST\u URI'
/index.php
起到了作用。如果
要处理
index.php/
index.php//
,我应该向
添加什么。当您使用
ORIG\u PATH\u INFO
时,您将始终获得
/index.php
使用
请求URI
。当您使用
ORIG\u PATH\u INFO
时,您将始终得到
/index.php

基于
$\u服务器['REQUEST\u URI']
的条件,而当url实际上不包含
index.php
时,它不会尝试重定向

并使用
stristr
搜索
index.php
在url中的任何位置


将您的条件建立在
$\u服务器['REQUEST\u URI']
上,当url实际上不包含
index.php
时,它不会尝试重定向

并使用
stristr
搜索
index.php
在url中的任何位置



您将/index.php重定向到/这意味着相同thing@safarov:是的,但它在url栏中看起来更好,我需要它是因为导航的原因。你也可以使用.htaccess文件。如果你愿意,我可以为你写一个解决方案htaccess@safarov:当然可以,但我需要将/index.php重定向到/的子文件夹应用规则,这意味着相同thing@safarov:是的,但它在url栏中看起来更好,我需要它是因为导航的原因。你也可以使用.htaccess文件。如果你愿意,我可以为你写一个解决方案htaccess@safarov:当然可以,但我需要规则来申请子文件夹,因为我在
requirest_URI
中遇到了同样的问题,这就是为什么我认为
ORIG_PATH_INFO
可能可以工作的原因,它现在似乎可以工作了,如果使用RewriteEngineEyes,是否有任何方法也可以检查index.php/和index.php//…?
RewriteRule^index.php[/]+$/[L]
rtrim($url,“/”)
(即删除尾随斜杠),然后再检查它是否以index.php结尾。我在
requirest_URI
中遇到了同样的问题,这就是为什么我认为
ORIG_PATH_INFO
可能会起作用,它现在似乎正在起作用,有没有办法也检查index.php/和index.php//…?
RewriteRule^index.php[/]+$/[L]
如果使用RewriteEngineEyes.
rtrim($url,“/”)
(即删除尾部斜杠)在您检查它是否以index.php.Ok结尾之前,它现在似乎正在工作,是否有任何方法也可以检查
index.php/
index.php///
?我想我建议使用
stristr
来检测任何包含index.php的url或其任何变体是的,但它可以包含在c的查询stringyes中ourse——如果您首先通过循环使用与
$\u服务器['QUERY\u string']相同数量的字符来减少url字符串
contains,你可以解释这一点好吧,它现在似乎正在工作,是否有任何方法也可以检查
index.php/
index.php///
?我想我建议使用
stristr
来检测包含index.php的url或其任何变体是的,但它可以包含在c的查询stringyes中ourse——如果您首先通过循环使用
$\u SERVER['QUERY\u string']
包含的尽可能多的字符来减少url字符串,您可以对此进行解释