Skip to content

When site uses Yoast SEO, the rewrite rule is conflicting and the one added by Yoast SEO takes precedence, causing 404 for /news-sitemap.xml #47

Open

Description

Describe the bug

Yoast SEO is adding rewrite rules by filtering the rewrite rules array using the filter option_rewrite_rules rather than using the add_rewrite_rule rule functionality and adds its sitemaps related rewrite rules at the top of the array.

As a result, the below rewrite rule added by Yoast SEO takes precedence :
[([^/]+?)-sitemap([0-9]+)?.xml$] => index.php?sitemap=$matches[1]&sitemap_n=$matches[2]

The rewrite rule that this plugin adds is [^news-sitemap.xml$] => index.php?news-sitemap=true.

As the regex "([^/]+?)-sitemap([0-9]+)?.xml$" catches the news-sitemap.xml, it is going to 404 page

This can be resolved by having the sitemap_slug to be different such that it is not caught by Yoast's rewrite rule regex "([^/]+?)-sitemap([0-9]+)?.xml$"

May be even allowing a filter to change the sitemap slug could work?

For now, the only option to make this working is to use the filter "option_rewrite_rules" and manually place the '^news-sitemap.xml$' related rule to the top of the array, making it take precedence over the Yoast SEO's rules.

Steps to Reproduce

  1. Have a website with Yoast SEO plugin Installed and activated
  2. Install this plugin
  3. Flush Permalinks
  4. Try visit your-site.com/news-sitemap.xml
  5. It shows 404.

Screenshots, screen recording, code snippet

No response

Environment information

not relevant

WordPress information

Encountered this on WordPress 6.6.2

Yoast SEO Version 22.7 and event the latest Version 23.4

Code of Conduct

  • I agree to follow this project's Code of Conduct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    type:bugSomething isn’t working.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions