【发布时间】:2020-10-17 15:45:08
【问题描述】:
在我从 Plesk (Web Pro) 启用 NGINX 后,我在主目录和子目录博客中的所有帖子都会出现 404 Page Not Found 错误。
我在 Plesk 的“附加 NGINX 指令”中放置了以下代码来修复所有 URL,但它只修复了主站点 (example.com) 而子目录 blogs (example.com/tech/, example .com/mag/ 和 example.com/dispatch/) 仍然给出 404 错误。
# Wordpress Permalinks
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
之后,我把代码去掉,放了下面的:
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
}
我在official Plesk pages 之一中找到了这段代码,上面写着:
如果 WordPress 安装位于子目录中(例如,“httpdocs/sub-dir”)或者这是基于子目录的 WordPress 多站点网络,请在 /index.php?$1 之前添加 /sub-dir/它看起来像这样:重写 ^/(.*)$ /sub-dir/index.php?$1; 注意:对于基于子文件夹的WordPress多站点网络,为每个子目录添加上述规则。
到目前为止,我得到了这个(不起作用):
if (!-e $request_filename) {
set $test P;
}
if ($uri !~ ^/(plesk-stat|webstat|webstat-ssl|ftpstat|anon_ftpstat|awstats-icon|internal-nginx-static-location)) {
set $test "${test}C";
}
if ($test = PC) {
rewrite ^/(.*)$ /index.php?$1;
rewrite ^/(.*)$ /tech/index.php?$1;
rewrite ^/(.*)$ /mag/index.php?$1;
rewrite ^/(.*)$ /dispatch/index.php?$1;
}
任何帮助将不胜感激!
附:主网站就像一个魅力。在 example.com/tech/ 和 /mag/ 和 /dispatch/ 中,虽然主页很好,但帖子给了我 404 页面错误。
【问题讨论】:
-
你试过设置->固定链接->保存设置吗?这将刷新 wordpress 重写规则。这也可能对您有所帮助:wordpress.org/support/article/nginx
-
已经做了,没有帮助。还有其他想法吗?
标签: wordpress nginx url plesk permalinks