WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
[resolved] FIX for sitemap_index.xml 404 error (30 posts)

  1. hadjedj.vincent
    Member
    Posted 2 years ago #

    Hi,

    Here is a little fix for some of us that have 404 errors on the sitemap_index.xml file with WordPress SEO plugin...

    Open your .htaccess file, and add this at the top of it :

    # WordPress SEO - XML Sitemap Rewrite Fix
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^sitemap_index\.xml$ /index.php?sitemap=1 [L]
    RewriteRule ^([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
    </IfModule>
    # END WordPress SEO - XML Sitemap Rewrite Fix

    It should work for most of us !

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. scrollpost
    Member
    Posted 2 years ago #

    LOL - one more thing!
    If you are running SuperCache and using a CDN (FYI I am using rackspace) this worked for me:

    Add in the SuperCache settings page -->> CDN tab -->> to the "exclude if substring" setting -->> .xsl

  3. gooma2
    Member
    Posted 2 years ago #

    Another thing if you're running W3 Total Cache and your sitemap index just shows up as a white page, Deactivate W3TC and then reactivate it.

    Seems to make that an easy fix thankfully!

  4. Johan82
    Member
    Posted 2 years ago #

    Yes it seems to work, the sitemap is showing up but it's still sending a 404 as the response header which means that Google Webmaster Tool won't find it.

    Any suggestions?

  5. hadjedj.vincent
    Member
    Posted 2 years ago #

    Yes, keep the modified .htaccess file and edit /wp-content/plugins/wordpress-seo/inc/class-sitemaps.php

    replace init() function (line 80) with :

    /**
    	 * Initialize sitemaps. Add sitemap rewrite rules and query var
    	 */
    	function init() {
    		global $wp_rewrite;
    		$GLOBALS['wp']->add_query_var( 'sitemap' );
    		$GLOBALS['wp']->add_query_var( 'sitemap_n' );
    		add_rewrite_rule( 'sitemap_index\.xml$', 'index.php?sitemap=1', 'top' );
    		add_rewrite_rule( '([^/]+?)-sitemap([0-9]+)?\.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top' );
    		$wp_rewrite->flush_rules();
    	}

    Regards

  6. Johan82
    Member
    Posted 2 years ago #

    I actually just managed to fix this. The problem was a plugin that had flush_rewrite_rules(); after a custom post type. So when I removed it, it worked.

    But thanks for the help anyway!

  7. hadjedj.vincent
    Member
    Posted 2 years ago #

    Can u give up the name of faulty plugin ?
    It can help the developer ;-)

    Regards

  8. Johan82
    Member
    Posted 2 years ago #

    It was actually my own plugin, not a public one, don't know why I added that, probably it was included in a tutorial i read when i created the custom post type way back when and can't remember where I read it, sorry.

  9. Jono Warren
    Member
    Posted 2 years ago #

    This has been frustrating me for ages, so thanks for finding a solution. I've adapted it for use with nginx, just add the following to the server block:

    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
  10. skipshean
    Member
    Posted 2 years ago #

    FINALLY this is resolved for me. THANK YOU so much for fixing this!

  11. derickschaefer
    Member
    Posted 2 years ago #

    Jonathan, thanks for the NGINX adaptation. I put this in the server block of our config and it works like a charm. What I don't understand, however, is why this isn't picked up when non-existent content is passed to index.php via

    if (!-e $request_filename) { rewrite . /index.php last; }

    Anyone have any insight?

  12. Jono Warren
    Member
    Posted 2 years ago #

    Hmm, maybe something to do with fastcgi_intercept_errors?

  13. ucarmetin
    Member
    Posted 2 years ago #

    Thanks hadjedj.vincent! The solution you provided worked for me.

  14. kredacter
    Member
    Posted 2 years ago #

    I'm new to nginx and I'm a little thrown when you say to add the fix to the server block. I added it to my config file, but I got no results. Can you explain so a fifth grader can understand how to insert the fix.

    PS: I'm not a fifth grader! Just need a simple step-by-step. lol...

    Thanks!

  15. Jono Warren
    Member
    Posted 2 years ago #

    Kredacter,

    You should insert the code in the server block for the site you want it work on, in my case I have multiple sites on one server so use multiple config files in my sites-available folder. You may have a single site configured in your main nginx.conf.

    So your server block should look something like this:

    server {
    
    	server_name  YourDomain.com;
    	root   /var/www/YourDomain/public;
    
    	#	Fix Yoast SEO Sitemaps
            rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    	rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    }

    Then you just need to tell nginx to re-read it's config files. In Ubuntu use the command service nginx reload. Hope that helps.

  16. kredacter
    Member
    Posted 2 years ago #

    Thanks Jonathan! I was able to get everything to work by making the change in my config file... But... :( I updated to the latest version of the plugin 1.1.3 and added the news module. Now a new problem. I get a 404 error when I submit to Google Webmaster Tools. The news sitemap returns a "not found" from the plugin xml sitemap dashboard as well as GWT. Any thoughts? Is anybody else having this problem?

  17. Jono Warren
    Member
    Posted 2 years ago #

    Hi Kredacter, glad to hear you got it working. All we're doing with this fix is telling the server to redirect the requests for the sitemaps to PHP. To get it working with the news module you'll have to:

    1. Find the sitemap name
    2. Find the PHP query string it should be redirected to
    3. Figure out the rewrite rule and add it your server block

    I haven't used the news module so I don't know what those things are, contacting the plugin author might be easiest: http://yoast.com/contact/

  18. newsfeedgadget
    Member
    Posted 2 years ago #

    One other thing to check....

    The XSL change in version 1.1.3 and above added the following file to the plugin: wordpress-seo/css/xml-sitemap-xsl.php.

    If you've "hardened" your wp-content folder via an .htaccess file to limit file types that browsers can call directly (e.g., to prevent php calls), you'll need to add the above file as an "exception".

    After:

    Order Allow,Deny
    Deny from all

    Add:

    <Files "xml-sitemap-xsl.php">
    Allow from all
    </Files>
  19. newsfeedgadget
    Member
    Posted 2 years ago #

  20. photoua
    Member
    Posted 2 years ago #

    Jonathan Warren thanks!
    It's working on my sites.

  21. ivnus
    Member
    Posted 2 years ago #

    Fixed...see below for Google News Sitemap Rewrite Rule

  22. ivnus
    Member
    Posted 2 years ago #

    Yoast Google News Plugin NGINX Rewrite Rules

    In order to get NGINX to redirect news_sitemap.xml to the sitemap PHP query, you will need to add the following to your server block, it should look something like this:

    server {
    
    	server_name  YourDomain.com;
    	root   /var/www/YourDomain/public;
    
    	#	Fix Yoast SEO Sitemaps
            rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    	rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
            rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;
    }

    This is the additional line that is required for the Google News Sitemap
    rewrite ^/news_sitemap\.xml$ /index.php?sitemap=wpseo_news last;

    Then you just need to tell nginx to re-read it's config files. In Ubuntu use the command service nginx reload. Hope that helps. - from Jonathan Warren.

  23. yogot7r
    Member
    Posted 2 years ago #

    I put the code from the very top of this forum to fix my sitemap error 404 problem. It fixed it so the sitemap worked but then all my pages and posts popped up the error 404. Any suggestions?

  24. Athen
    Member
    Posted 2 years ago #

    hadjedj.vincent YOU ROCK! ;)

  25. Elan42.com
    Member
    Posted 2 years ago #

  26. Devin Walker
    Member
    Posted 2 years ago #

    Thanks guys, I'm running NGINX and was having this problem... Luckily, WP Community saves the day once again!

  27. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    Nice to see this worked out well for all of you ;)

  28. Joost de Valk
    Member
    Plugin Author

    Posted 2 years ago #

    Mod, can you resolve this one? I can't...

  29. adevandry
    Member
    Posted 2 years ago #

    I had a similar problem. Turns out my site was using 1and1 to host, and they still had the site set to PHP4. I changed that setting to PHPdev in the 1and1 Control Panel and it solved the 404 error on sitemap_index.xml

  30. Ov3rfly
    Member
    Posted 1 year ago #

    I had a similar problem with another sitemap xml plugin.

    Google Webmaster Tools complained about a 404 not found for the /sitemap.xml url, but the xml was visible in browser.

    Some testing showed that WordPress adds a 404 header to all feeds, including the sitemap xml feed, if no posts exist in the website.

    Not sure if this affects also the Yoast plugin, but thought I would share the info here for others like me who find this thread when looking for a solution.

    More details and a hotfix here:
    http://wordpress.org/support/topic/sitemap-xml-feed-is-shown-but-404-header-added-by-wordpress-if-site-has-no-posts

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic