PHP使用header函数301重定向无法跳转是什么原因

PHP与SEO 投稿&转载 879浏览

最近解除了tag标签robots.txt封禁,但是旧url有所修改,所以打算使用header301重定向。但是在使用过程中出现跳转失败的问题,那么,一般情况下,出现这种情况可能是什么原因呢?

解决方法:

  1. 修改php.ini;
  2. 找到 output_buffering=Off 将其修改为 output_buffering=4096;
  3. 重启服务器。

在PHP中用header("location:test.php")进行跳转要注意以下几点:

  1. location和“:”号间不能有空格,否则会出错.
  2. 在用header前不能有任何的输出,包括include的页面中标签“?>”后不能有空格.
  3. header后的PHP代码还会被执行.

PHP的 header 跳转之前不能有任何内容输出,因为PHP开始执行的时候就已经向浏览器送出HTTP头信息,之后就不再允许更改了。

但是如果必须要在输出之后再处理header信息的话可以使用 ob_start() ob_end_flush() 来缓存一下要发送的内容,等到header继续再发送内容。

推荐阅读

Function get_magic_quotes_gpc() is deprecated报错解决办法

在 PHP 7.4 及更高版本中, get_magic_quotes_gpc() 函数已被弃用。 This means that code using this function will raise a warning or error.以下是解决......

PHP提示:Warning: count():Parameter must be an array or an object that implements Countable

错误原因:PHP7.2以后,count()函数的参数无效时会抛出warning警告。...

PHP7.4 报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated.

PHP7.4运行项目报错:Deprecated Functionality: implode(): Passing glue string after array is deprecated。只需交换 implode() 函数的两个参数!...