当前位置:网站首页 > WordPress教程 > 正文
All in One SEO Pack插件sitemap.xml 404的解决办法
作者:98wpeu发布时间:2026-03-21分类:WordPress教程浏览:8
导读:相信很多人在给网站生成sitemap.xml文件的时候都是使用的GoogleXMLSitemaps这款插件,之前也是,后来发现AllinOneSEOPack的功能里面实...
相信很多人在给网站生成sitemap.xml文件的时候都是使用的Google XML Sitemaps这款插件,之前也是,后来发现All in One SEO Pack的功能里面实际上自带了一个sitemap生成的组件,就没有使用Google XML Sitemaps来生成了。
刚才突然发现sitemap.xml 404了,切换到Google XML Sitemaps同样是404,不知道是什么原因,这两天就折腾了文件缓存(看了下规则,应该就是xml设置了缓存8天导致的404,把xml排除出去就可以了。)下面说下sitemap.xml文件404的解决办法。
出现404的情况基本上都是伪静态配置的问题。
例如写这篇文章的时候突然发现原来是我折腾文件缓存的时候把xml文件也缓存了,去掉缓存规则就可以了。
sitemap.xml 404的解决办法
更保险的方法是给sitemap.xml添加伪静态规则。
以下两个伪静态规则测试都有效。
Google XML Sitemaps这款插件推荐的nginx规则
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;
All in One SEO Pack推荐的规则
#rewrite rules for AIOSEOP XML Sitemap rewrite ^/sitemap.xml$ /index.php?aiosp_sitemap_path=root last; rewrite ^/sitemap_(.+)_(\d+).xml$ /index.php?aiosp_sitemap_path=$1&aiosp_sitemap_page=$2 last; rewrite ^/sitemap_(.+).xml$ /index.php?aiosp_sitemap_path=$1 last; rewrite ^/sitemap.xml.gz$ /index.php?aiosp_sitemap_path=root.gz last; rewrite ^/sitemap_(.+)_(\d+).xml.gz$ /index.php?aiosp_sitemap_path=$1.gz&aiosp_sitemap_page=$2 last; rewrite ^/sitemap_(.+).xml.gz$ /index.php?aiosp_sitemap_path=$1.gz last;
Nginx伪静态规则添加方法
只需要将上面的伪静态规则添加到你虚拟主机的nginx配置文件,然后重启nginx即可。
LNMP一键包的用户,直接添加到include rewrite/wordpress.conf;这串代码上面。
宝塔面板用户,在你网站的伪静态规则里面添加上面的代码即可。
其他注意事项
如果你使用了缓存插件,那么记得把下面这两个页面都添加到例外,以免出现游客访问缓存页面出错的情况。
sitemap.xml
sitemap.xsl
相关推荐
- WordPress官方推荐的4款恶意软件扫描插件
- WordPress批量查找替换修改文章内容的插件和代码
- 记录WordPress用户登录历史的插件:User Login History
- 多功能的WordPress优化插件:WPJAM Basic
- 允许WordPress评论者限时修改评论内容插件Simple Comment Editing
- WordPress让不同国家访客访问不同页面的插件:IP2Location Redirection
- WordPress禁用特定插件的更新提示
- 很好用的WordPress优化速度插件推荐:Hummingbird
- 免插件实现一键填写网站评论框信息
- 隐藏文章作者和发布日期的WordPress插件
- WordPress教程排行
- 最近发表


