nginx对wordpress的sitemap插件生成的URL进行rewrite
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; |
参考
Recent Comments