• Resolved Joe Dooley

    (@joedooley)


    I was hoping you guys could help me out with the nginx rewrite rules that I need to add to get the XML Sitemaps feature working. I have looked everywhere for help on this and have failed several times trying to implement on my own.

    The catch is that Pantheon, https://pantheon.io, requires rewrite rules to be added to the wp-config.php file. Here is a link to their documentation explaining how to include redirects and rewrites, https://pantheon.io/docs/articles/sites/code/redirect-incoming-requests/

    Can you help me figure out how to add your nginx redirect code to the wp-config.php file?

    rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

    Thanks in advance!

    https://www.ads-software.com/plugins/wordpress-seo/

Viewing 11 replies - 1 through 11 (of 11 total)
  • okaiji

    (@okaiji)

    +1 for this! I was gonna try out other plugins, and those prompted the same messages about nginx rewrites too.

    Thread Starter Joe Dooley

    (@joedooley)

    Hi Okaiji. Yeah I’ve searched far and wide and haven’t had any luck. I reached out to Yoast and they wouldn’t help unless I purchased their plugin, but they wouldn’t gaurantee a solution.

    I guess I’ll ask https://pantheon.io to write a supporting article that lists. Additional wp-config rewrites.

    I’m assuming you haven’t had any luck?

    Not resolved yet, should give pantheon a buzz

    silverliebt

    (@silverliebt)

    I’m having an issue getting xml sitemaps (via Yoast SEO) to work on Pantheon.io as well. I just submitted a ticket – will report back when I hear back from support.

    stuartbrameld

    (@stuartbrameld)

    hey guys, we’ve just noticed this issue too, got the following response from Pantheon. pretty gobsmacked by this, we’re using Yoast which is probably the most used WordPress plugin and it doesn’t work, and displays no errors.

    From Pantheon:
    It is possible to use the plugin, the difference being that on Pantheon the only writeable location on server is wp-content/uploads/.
    You can thus create a symlink to point https://www.colt.net/some/path/to/sitemap.xml to wp-content/uploads/. I’ve pasted an article on how to achieve this below.
    Non-Standard Files Locations – https://pantheon.io/docs/articles/sites/files/non-standard-files-locations/
    If you have any further issues please let us know.
    Kind regards
    Mike Richardson

    Josh Koenig

    (@outlandish-josh)

    Hey there; I’m one of the co-founders of Pantheon, and just wanted to explain what’s going on here.

    By defauly, Yost’s SEO plugin (like many other WP plugins) assumes it can write files to any location. While writing an XML file is pretty safe, this basic capability is the root cause of the issues with WordPress sites being used to clickjack, distribute malware, or turned into a node on someone else’s botnet. Running a website under a permissions schema that allows it to modify its own code is risky.

    On Pantheon, WordPress is restricted to writing to the uploads directory only in production. Moreover, we don’t allow code to be executed there. This means that sites cannot be fooled into executing malicious scripts, modifying its own theme to include malware or clickjack links, etc.

    However, it also means that you can’t write an XML file to the docroot of the site.

    The SEO plugin allows you to configure the location the sitemap.xml, and you can fix the browser experience with a symlink. It’d be even better if the plugin could “own” the /sitemap.xml path and deliver it, but that would require a change on their end.

    iatkotep

    (@iatkotep)

    @josh,

    I am having this exact same problem on Pantheon. You say one can specify the location of the xml sitemap in the Yoast SEO plugin. I can not find where to do that. Can you be more specific?

    sAustinPower

    (@saustinpower)

    Hi Josh – Thank you for the reply, that was helpful (we are also running into this same issue). However, I am not seeing any options within the Yoast SEO plugin to configure the location of the sitemap.xml file as you suggest, nor can I find any information online regarding how to do so. Can you please expand upon this?

    rachelwhitton

    (@rachelwhitton)

    Hey everyone, I help manage Pantheon’s docs and wanted to give some clarification. We recommend using PHP for redirect logic. For the original comment here, you can add the following within wp-config.php to redirect requests for sitemap.xml to sitemap_index.xml:

    // 301 Redirect from /sitemap.xml to /sitemap_index.xml
    if (($_SERVER['REQUEST_URI'] == '/sitemap.xml') &&
      (php_sapi_name() != "cli")) {
      header('HTTP/1.0 301 Moved Permanently');
      header('Location: /sitemap_index.xml');
      exit();
    }

    Sitemaps are only accessible on the live environment for sites with a custom domain.

    If you’re running an older version of this plugin, that’s when you might encounter issues accessing sitemaps generated as static files. To resolve, we suggest running the lastest version of the plugin. Details on the decision to stop writing sitemaps as static files can be found in the following blog post from 2011: https://yoast.com/xml-sitemap-in-the-wordpress-seo-plugin/

    iatkotep

    (@iatkotep)

    I fixed this.

    I took the rewrite rules that were specified for nginx/conf, and I translated them to make use of the WordPress Rewrite API.

    the following block of code in your functions.php file should get you where you need to go

    function wp_api_sitemap_rewrites() {
      add_rewrite_rule('^sitemap_index.xml$', '/index.php?sitemap=1', 'top');
      add_rewrite_rule('^locations.kml$', '/index.php?sitemap=wpseo_local_kml', 'top');
      add_rewrite_rule('^geo_sitemap.xml$', '/index.php?sitemap=geo', 'top');
      add_rewrite_rule('^([^/]+?)-sitemap([0-9]+)?.xml$', '/index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top');
      add_rewrite_rule('^([a-z]+)?-?sitemap.xsl$', '/index.php?xsl=$matches[1]', 'top');
    }
    add_action('init', 'wp_api_sitemap_rewrites');
    Thread Starter Joe Dooley

    (@joedooley)

    Hi guys,

    I just wanted to let you guys know that I haven’t had a problem with Yoast SEO sitemaps on Pantheon in about 6 months. I have over a dozen sites using Yoast’s XML sitemap feature on Pantheon. I haven’t made any modifications to get things working either. One day it just started working. That was over 5 months ago. Take a look at a client’s current XML sitemap generated via SEO for WordPress by Yoast plugin.

    Yoast Sitemap Screenshot

    Also here is a screenshot from Google Webmaster Tools of that same sitemap above that I just resubmitted. Are you guys using an out of date version of Yoast? I don’t even get the redirect warning anymore about have to add code to the nginx config.

    GWT Screenshot of resubmitted sitemap hosted on Pantheon

    Hope this helps rather than frustrates. Josh, I’ll mark the issue as resolved. I forgot about this post when the issue was resolved a while back.

    Thanks,
    Joe Dooley

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Help! Pantheon Hosting XML sitemaps. Must add rewrite code to wp-config’ is closed to new replies.