WordPress网站迁移到阿里云云虚拟主机后,只能看到首页,看不到文章页和栏目页,后台也无法登录。
很对问题我做了如下操作:
1、检查 Apache 的 rewrite mod 是否开启。
LoadModule rewrite_module modules/mod_rewrite.so
2、检查 Apache 的对应目录 Allowoverride 是否设为 All。
(这次就在这里栽跟头了,子目录覆盖了主目录设置)
<Directory “/var/www/html/test”>
AllowOverride All
</Directory>
3、检查 WordPress 主目录下是否有正确设置的 .htaccess 文件。(重点检查!)
默认设置如下,特别注意迁移后可能的目录更改。
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
如果网页服务器不是 Apache,而是 Nginx。
则需要在网站设置中增加以下代码。
参考文章:解决nginx下WordPress伪静态只能打开首页:wordpress网站从apache虚拟主机迁移到nginx虚拟主机,只能打开首页,文章页和后台地址都打不开
以上操作完成后,文章页和栏目页都能打开了,但后台打开失败,显示空白。打开wordpress的debug选项后,登录后台页报如下错误:
Warning: Cannot modify header information - headers already sent by (output started at /data/home/xxxxxxxxxx/htdocs/wp-config.php:1) in /data/home/xxxxxxxxxx/htdocs/wp-includes/pluggable.php on line 1329
Warning: Cannot modify header information - headers already sent by (output started at /data/home/xxxxxxxxxx/htdocs/wp-config.php:1) in /data/home/xxxxxxxxxx/htdocs/wp-includes/pluggable.php on line 1332
上网查了一些资料,说是我的php.ini里面的配置出了问题,找到php.ini文件中的output_buffering默认为off的,把它改为on;我通过这一方法解决了问题,阿里云虚拟主机操作方法如下图:

其它网友遇到类似问题,还做了如下操作:
setcookie函数必須在任何资料输出至浏览器前,就先送出
基于上面這些限制,所以執行setcookie()函数时,常会碰到”Undefined index”、”Cannot modify header information – headers already sent by”…等问题,解決”Cannot modify header information – headers already sent by”這個錯誤的方法是在产生cookie前,先延缓资料输出至浏览器,因此,您可以在程式的最前方加上ob_start()函數。
ob_start()函数用于打开缓冲区,比如header()函数之前如果就有输出,包括回车\空格\换行\都会有”Header had all ready send by”的错误,这时可以先用ob_start()打开缓冲区PHP代码的数据块和echo()输出都会进入缓冲区而不会立刻输出:
通过以下方法,问题得到解决:
//在header()之前
ob_start(); //打开缓冲区
echo \”Hellon\”; //输出
header(“location:index.php”); //把浏览器重定向到index.php
ob_end_flush();//输出全部内容到浏览器
?>