Wordpress 默認使用 apache 的 URL 改寫,一般修改.htaccess 文件即可。如果使用 nginx+php-fpm 模式的伺服器,需要自己進行重寫 URL。 nginx+php-fpm 模式下,Yoast SEO 和 Google Sitemap Generator 兩款 Sitemap 插件可以使用以下配置實現 Nginx 對 SitemapURL 的重寫。
Yoast SEO
#Yoast sitemap
location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ {
## this redirects sitemap.xml to /sitemap_index.xml
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
## this makes the XML sitemaps work
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;
## The following lines are optional for the premium extensions
## News SEO
rewrite ^/news-sitemap\.xml$ /index.php?sitemap=wpseo_news last;
## Local SEO
rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last;
rewrite ^/geo-sitemap\.xml$ /index.php?sitemap=wpseo_local last;
## Video 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/