解决 WP迁移后出现的404错误

large_parts_wordpress

项目迁移  后仅首页正常,其它页面全部 404。
时隔一年,再度遇到这问题,总结和梳理一下。

1、想办法登录后台,刷新一次“设置”中的“固定链接”
比如换成默认后保存,再设回原先设置并保存,理论上就可以解决绝大多数人的问题了。

2、检查  的 rewrite mod 是否开启

LoadModule rewrite_module modules/mod_rewrite.so

3、检查  的对应目录 Allowoverride 是否设为 All
(这次就在这里栽跟头了,子目录覆盖了主目录设置)

<Directory "/var/www/html/test">
    AllowOverride All
</Directory>

4、检查  主目录下是否有正确设置的 .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

如果网页服务器不是 ,而是 
则需要在网站设置中增加以下代码。

location / {
    try_files $uri $uri/ /index.php?$args; 
}

5、检查  整个目录是否为 755 权限(文件 644 权限)。
(Window 系统下大概不用管后两条)

find /path/to/wordpress/ -type d -exec chmod 755 {} ;
find /path/to/wordpress/ -type f -exec chmod 644 {} ;
chown -R apache:apache /path/to/wordpress/

修改所有者为 apache 以应对缓存/上传/更新等问题。
用户名因人而异,还可能是 www/daemon 等。
(还要注意检查后台“多媒体-默认上传路径”)

6、如果配置的是虚拟主机那么记得在配置文件中加入开启伪静态的功能

<VirtualHost *:80>
DocumentRoot D:/www
ServerName localhost

RewriteEngine on
#规则放在下面即可

</VirtualHost>

可以对每个虚拟主机做单独的URL Rewrite
原文地址:https://www.cnblogs.com/kenshinobiy/p/6723030.html