php重定向在某些位置不起作用 [英] php redirect not working on some locations
问题描述
我有一个奇怪的问题,不容易解决,也不知道为什么!!我有一个文件夹,我在其中放置了一个普通的 php 重定向代码:<?Header("HTTP/1.1 301 永久移动");Header( "位置:http://www.mydomain.com");?>
I have weird problem that can't be solved easily and don't know really why!! I have a folder where I placed a plain php redirect code: <?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.mydomain.com" );
?>
这很好用,但是当我将确切的文件复制到另一个不同的文件夹时,重定向不起作用.加载后页面本身停止!!
and this works fine, but when I copy exact file to another different folder, the redirect doesn't work. The page itself stops after loading !!
我使用了另一个代码,但仍然无效.
I used another code, but still didn't work.
error_reporting(E_ALL | E_WARNING | E_NOTICE);
ini_set('display_errors', TRUE);
flush();
header("Location: http://www.website.com/");
die('should have redirected by now');
P.S> 在我放置 index.php 的文件夹中没有包含重定向的内容.
P.S> there is nothing in folders where I placed index.php that contain the redirect.
有什么想法吗??
感谢您的意见.
谢谢
解决方案:
我在这里原始问题"中包含的代码运行良好,但似乎 php 不能很好地与 underscore (_)一起使用代码>如果包含在文件夹的名称或目录名称中.当我从目录名称中删除下划线时,事情又恢复了.我希望任何人都觉得这个解决方案很有用.谢谢
The codes I included in here "original question" works perfectly, but it seems that php doesn't work well with underscore (_)
if contained in the folder's name or directory name. when I removed the underscore from the directory's name, things worked back again. I hope anyone finds this solution useful. Thanks
推荐答案
我会检查您的代码中是否有任何空格(甚至是编码,因为某些编码会在文件的开头放置一个字符).还要确保在 header
调用之前包含在脚本中的文件中没有输出.
I would check for any whitespace in your code (even the encoding, since some encodings put a character at the beggining of the file). Also make sure there is no output in the files you are including into your script perior to header
call.
如果你只把它放在文件中,下面的代码应该不会失败:
The code below should not fail if you only put this in the file:
<?php
header("Location: http://www.website.com/");
exit;
?>
或者你可以使用 javasctipt:
Alternatively you could use javasctipt:
<script type="text/javascript">
<!--
window.location = "http://www.website.com/";
//-->
</script>
这篇关于php重定向在某些位置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!