banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

nginxは、WordPressのサイトマッププラグインが生成するURLをリライトします。

WordPress はデフォルトで Apache の URL リライトを使用していますが、通常は.htaccess ファイルを変更するだけで済みます。nginx+php-fpm モードのサーバーを使用している場合は、URL のリライトを自分で行う必要があります。nginx+php-fpm モードでは、Yoast SEO と Google Sitemap Generator の 2 つのサイトマッププラグインを使用して、Nginx による SitemapURL のリライトを実現するための以下の設定を使用できます。

Yoast SEO

#Yoast サイトマップ
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
## これにより、sitemap.xml が /sitemap_index.xml にリダイレクトされます
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
## これにより、XML サイトマップが機能します
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;
## 以下の行はプレミアム拡張機能のためのオプションです
## ニュース SEO
rewrite ^/news-sitemap\.xml$ /index.php?sitemap=wpseo_news last;
## ローカル SEO
rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
rewrite ^/geo-sitemap\.xml$ /index.php?sitemap=wpseo_local last;
## ビデオ SEO
rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last;
}

Google Sitemap Generator

rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?.xml$ "/index.php?xml_sitemap=params=$2" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?.xml.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;

参考 https://easyengine.io/wordpress-nginx/tutorials/plugins/yoast-seo-sitemap/ http://www.ehowstuff.com/multiple-wordpress-sites-on-nginx/

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。