Sitemap Rewrite Rule is Not Working on NGINX Server

#240817
  • Resolved Vijay Yogi
    Rank Math free

    Hi there,

    My WordPress is hosted on the Nginx server and I have the latest rank math plugin. I have already added the rank math sitemap rewrite rule on my /etc/nginx/sites-available/example.com file and this was working fine till now.

    But yesterday I updated my WP to 5.8 and Rankmath to 1.0.69.2 and after that example.com/sitemap_index.xml is working fine but https://example.com/post-sitemap.xml is not working. It just giving 302 error and keep redirecting.

    But I got this solved by replacing $ with / in the rewrite rule.

    Here the previous rule:

    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps

    Here are the changes I made and working fine:

    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml/ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml/ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps

    I just want to know if this rewrite rule is right and will it create any other conflicts in the future. DO you recommend this?

    Because I tried every method listed here and none of them worked except replacing $ with /.

    I don’t know why this happens my other two blogs hosted on the same Nginx server are working fine, but the remaining two create this problem. ( I have a total of 4 WordPress blogs hosted on the same nginx droplet and all of them are using rank math and the sitemap rewrite rule is added to every blog’s server directory. i.e /etc/nginx/sites-available/blog1 and /etc/nginx/sites-available/blog2 like this.)

Viewing 7 replies - 1 through 7 (of 7 total)
  • Ankit
    Rank Math business

    Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention.

    The Sitemap URL you have shared in the sensitive data section appears to be working.

    Clear the website cache and Rank Math Transients by going to Rank Math > Status & Tools > Database Tools > Remove transients
    transietns

    Also, If you manage your hosting, Consider restarting the nginx server and check if you are able to see the sitemap of your remaining website?

    Looking forward to helping you. Thank you.

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Yes, I myself manage my server setup with nginx. I tried all the steps listed below but the problem still exists.

    1. Clearing WP-Rocket (Cache Plugin), Cloudflare, FastCGI Cache.
    2. Database Cleanup, Removing Rankmath and other Transients.
    3. Switching to an older version of rank math. (Just up to 1.0.69) and disabling all plugins.
    4. Plugins like Yoast SEO working fine with the sitemap. (Already removed plugin and data from the database after seeing the problem is with RankMath only).

    Let me tell you as I said above I have four WordPress sites hosted on one nginx server and out of these two are working fine but the remaining two have problems with the post-sitemap.xml and page-sitemap.xml

    Problem ———
    1. examle.com/sitemap_index.xml (works fine) but
    2. example.com/post-sitemap.xml or example.com/page-sitemap.xml is throwing 302 error and keeps redirecting and not loads.

    The solution worked for me ———

    # START Nginx Rewrites for Rank Math Sitemaps
    rewrite ^/sitemap_index.xml/ /index.php?sitemap=1 last;
    rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml/ /index.php?sitemap=$1&sitemap_n=$2 last;
    # END Nginx Rewrites for Rank Math Sitemaps

    (Replacing $ variable with / ) in two sites which does not load post-sitemap.xml

    I have updated the sensitive data with another site that currently has a problem and I have not replaced the $ variable with / in the rank math sitemap rewrite rule.

    Here is the header output for the same. I replaced site with example.com, consider site 2 (i.e last two-line added in sensitive data).

    Request URL: https://example.com/post-sitemap.xml
    Request Method: GET
    Status Code: 302
    Remote Address: 104.21.47.186:443
    Referrer Policy: same-origin
    alt-svc: h3-27=”:443″; ma=86400, h3-28=”:443″; ma=86400, h3-29=”:443″; ma=86400, h3=”:443″; ma=86400
    cf-cache-status: DYNAMIC
    cf-ray: 67c294c13ec01da5-BLR
    content-security-policy: default-src ‘self’ https: data: ‘unsafe-inline’ ‘unsafe-eval’;
    content-type: text/html; charset=UTF-8
    date: Mon, 09 Aug 2021 17:07:30 GMT
    expect-ct: max-age=604800, report-uri=”https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct”
    fastcgi-cache: BYPASS
    location: https://example.com/post-sitemap.xml
    nel: {“success_fraction”:0,”report_to”:”cf-nel”,”max_age”:604800}
    permissions-policy: geolocation=();notifications=(self);push=(self);payment=();camera=();microphone=();speaker=(self);fullscreen=(self);
    referrer-policy: same-origin
    report-to: {“endpoints”:[{“url”:”https:\/\/a.nel.cloudflare.com\/report\/v3?s=U5TpHwq0ludZyP8j6SJN%2BBu52P0gIsnhJ4Y1gmUkYBnEJvUjHsJw6MrjBtVEqeXqunCfproe03%2BGGGO23z8hSnEnDNi6EfQ0PRCmZkXo6HIdDwNCoNOW5PcSPTqD1ZSD”}],”group”:”cf-nel”,”max_age”:604800}
    server: cloudflare
    strict-transport-security: max-age=31536000; includeSubDomains; preload
    x-content-type-options: nosniff
    x-frame-options: SAMEORIGIN
    x-redirect-by: WordPress ( I don’t know why this is showing)
    x-xss-protection: 1; mode=block
    :authority: example.com
    :method: GET
    :path: /post-sitemap.xml
    :scheme: https
    accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    accept-encoding: gzip, deflate, br
    accept-language: en-IN,en;q=0.9
    cache-control: max-age=0
    referer: https://example.com/sitemap_index.xml/
    sec-ch-ua: “Chromium”;v=”92″, ” Not A;Brand”;v=”99″, “Google Chrome”;v=”92″
    sec-ch-ua-mobile: ?0
    sec-fetch-dest: document
    sec-fetch-mode: navigate
    sec-fetch-site: same-origin
    upgrade-insecure-requests: 1
    user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

    Hi there, could you please tell me where is the sitemap code or file is located in rank math plugin zip file downloaded from WordPress.

    I tried to roll back to every rankmath plugin and found that the issue of post-sitemap.xml not working starts after version 1.0.66.1 (free). I just want to replace only sitemap code or file in ranmath version 1.0.69.2 (latest version).

    If you could tell me where is the sitemap PHP code or file is located in the zip file of the plugin. I will manually do that.

    Thanks.

    Hello,

    The sitemap links added in the Sensitive Data field seem to work correctly right now, I assume you rolled back to version 1.0.66.1, as mentioned in your last reply.

    Most of the code related to the sitemaps is located in the seo-by-rank-math/includes/modules/sitemap folder, but unfortunately, it might not be as easy as replacing the files to make it work, because there were many changes in the files since the version in question, and related codes in other files may have been changed as well.

    I went through the changelogs to see recent changes made to the sitemap since that version. Because of the 302 redirects you mentioned I’m suspecting it is related to this change in version v1.0.67:

    Improved: Sitemap was accessible even after adding zeros to the URL. It should only be accessed via its URL now

    You can disable this new functionality by deleting line number 167 in seo-by-rank-math/includes/modules/sitemap/class-sitemap-xml.php. This is the line that should be deleted:
    $this->maybe_redirect( $current_page );

    Please try this change after re-installing the latest version, and let us know if this solves the issue on your site. Thank you.

    Hi

    I tried this but still not working. This is a very serious error and I am facing the same issue on two sites hosted on the nginx server. I am totally fed up now. I can provide you WordPress login detail if could look it up.

    Hello,

    I’m sorry my suggestion did not help with the issue.

    Please do share the WP login details (and possibly the FTP access details as well) to a site where the issue is happening, so we can try some changes in the plugin code, to find out why this issue is happening. Please use the Sensitive Data field for this.

    Thank you. Looking forward to your response.

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this ticket.