wordpress设置“固定链接”后,页面404错误的解决方法

Nginx 解决方案:

网上盛传的方法是:

在 /etc/nginx/nginx.conf文件的 loction / {} 中添加

复制代码
if (-f $request_filename/index.html){
    rewrite (.*) $1/index.html break;
}

if (-f $request_filename/index.php){
    rewrite (.*) $1/index.php;
}

if (!-f $request_filename){
    rewrite (.*) /index.php;
}
复制代码

特别注意:这种设置方法小编测试是无效的,会导致网站排版乱码。

正确的设置方式是loction / {}中添加配置:

复制代码
#加入如下一条命令即可
try_files $uri $uri/ /index.php?$args;
复制代码

修改完成后重启Nginx服务器生效。

service nginx restart

Apache解决方案:

/etc/httpd/conf/httpd.config 文件

原因一:Apache中的rewrite模块没有开启,去除这一行前面的#号就可以了

LoadModule rewrite_module modules/mod_rewrite.so

原因二:AllowOverride Not Enabled;服务器可能没打开AllowOverride。如果httpd.config的AllowOverride设置的是None,那.htaccess将被忽略。找到以下2处位置并修改:

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html>
# … other directives…
AllowOverride All
</Directory>

修改完成后,要重启Apache才能生效。

service httpd restart
原文地址:https://www.cnblogs.com/whiterock/p/7232383.html