php重定向在某些位置不起作用

编程入门 行业动态 更新时间:2024-10-24 14:19:10
本文介绍了php重定向在某些位置不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个奇怪的问题,不容易解决,也不知道为什么!!我有一个文件夹,我在其中放置了一个普通的 php 重定向代码:<?Header("HTTP/1.1 301 永久移动");Header( "位置:www.mydomain");?>

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: www.mydomain" ); ?>

这很好用,但是当我将确切的文件复制到另一个不同的文件夹时,重定向不起作用.加载后页面本身停止!!

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: www.website/"); 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: www.website/"); exit; ?>

或者你可以使用 javasctipt:

Alternatively you could use javasctipt:

<script type="text/javascript"> <!-- window.location = "www.website/"; //--> </script>

更多推荐

php重定向在某些位置不起作用

本文发布于:2023-11-23 01:17:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619593.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   不起作用   位置   在某些   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!