WordPress 在子目录中的单一安装 站点地图重写规则 nginx.



我在另一个wordpress安装的子目录中有一个单独的wordpress安装。子目录的名称是"blog"(这不是多站点设置(。我对nginx的重写规则是:

location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
# Rules for yoast sitemap with wp|wpsubdir|wpsubdomain
rewrite ^.*sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^.*/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
}

站点地图是为 example.com/sitemap_index.xml 和 example.com/blog/sitemap_index.xml 生成的,但两者都是相同的,并且不包含子目录(博客(中第二个安装的帖子。我知道这与子文件夹的重写规则配置有关,但我无法弄清楚问题到底是什么。我正在使用 Yoast 插件,并在两个安装(即根文件夹和子文件夹(上分别安装了 Yoast 插件。

我得到了这个工作。所以基本上问题是nginx重写规则,这是最新版本的简易引擎附带的。由于默认情况下不习惯在子目录中安装单个wordpress,因此您需要稍微修改这些规则。

所以改变:

rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
rewrite ^.*sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^.*/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

rewrite ^$dir1/sitemap.xml$ $dir1/sitemap_index.xml permanent;
rewrite ^$dir1/([a-z]+)?-?sitemap.xsl$ $dir1/index.php?xsl=$1 last;
rewrite ^$dir1.*sitemap_index.xml$ $dir1/index.php?sitemap=1 last;
rewrite ^$dir1.*/([^/]+?)-sitemap([0-9]+)?.xml$ $dir1/index.php sitemap=$1&sitemap_n=$2 last;

其中 $dir 1 显然是您的子目录,您可以通过在位置块中检查它来分配它。

最新更新