WordPress rewrite_rules order is wrong

After an export with migrate DB, my rewrite rules are not in a good order, and I can’t fix it in database because when I regenerate them, it happens again.

I don’t know if it’s related to the plugin or not.

Read More

What I call my rules are the rules added with my custom post types.

So, the rules should begin with MY RULES first (from custom post types), but it starts with

.?.+?/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]

and this rule and the ones that follow it (I checked in other wordpress databases) should be near the end of the array.

My problem is that there is a rule after this one that break every page in my site (because it’s too generic and catch everything), it’s this one :

"(.?.+?)(/[0-9]+)?/?$ => index.php?pagename=$matches[1]&page=$matches[2]"

I’ve debugged it but I cannot resolve it.

Here’s the order:

".?.+?/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]"
".?.+?/attachment/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
".?.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
".?.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
".?.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"
"(.?.+?)/trackback/?$ => index.php?pagename=$matches[1]&tb=1"
"(.?.+?)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?pagename=$matches[1]&feed=$matches[2]"
"(.?.+?)/(feed|rdf|rss|rss2|atom)/?$ => index.php?pagename=$matches[1]&feed=$matches[2]"
"(.?.+?)/page/?([0-9]{1,})/?$ => index.php?pagename=$matches[1]&paged=$matches[2]"
"(.?.+?)/comment-page-([0-9]{1,})/?$ => index.php?pagename=$matches[1]&cpage=$matches[2]"
"(.?.+?)/wc-api(/(.*))?/?$ => index.php?pagename=$matches[1]&wc-api=$matches[3]"
"(.?.+?)/order-pay(/(.*))?/?$ => index.php?pagename=$matches[1]&order-pay=$matches[3]"
"(.?.+?)/order-received(/(.*))?/?$ => index.php?pagename=$matches[1]&order-received=$matches[3]"
"(.?.+?)/view-order(/(.*))?/?$ => index.php?pagename=$matches[1]&view-order=$matches[3]"
"(.?.+?)/edit-account(/(.*))?/?$ => index.php?pagename=$matches[1]&edit-account=$matches[3]"
"(.?.+?)/edit-address(/(.*))?/?$ => index.php?pagename=$matches[1]&edit-address=$matches[3]"
"(.?.+?)/lost-password(/(.*))?/?$ => index.php?pagename=$matches[1]&lost-password=$matches[3]"
"(.?.+?)/customer-logout(/(.*))?/?$ => index.php?pagename=$matches[1]&customer-logout=$matches[3]"
"(.?.+?)/add-payment-method(/(.*))?/?$ => index.php?pagename=$matches[1]&add-payment-method=$matches[3]"
".?.+?/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
".?.+?/attachment/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"(.?.+?)(/[0-9]+)?/?$ => index.php?pagename=$matches[1]&page=$matches[2]"

// my rules ...

".*wp-(atom|rdf|rss|rss2|feed|commentsrss2).php$ => index.php?feed=old"
".*wp-app.php(/.*)?$ => index.php?error=403"
".*wp-register.php$ => index.php?register=true"
"feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]"
"(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]"
"page/?([0-9]{1,})/?$ => index.php?&paged=$matches[1]"
"comment-page-([0-9]{1,})/?$ => index.php?&page_id=20&cpage=$matches[1]"
"wc-api(/(.*))?/?$ => index.php?&wc-api=$matches[2]"
"order-pay(/(.*))?/?$ => index.php?&order-pay=$matches[2]"
"order-received(/(.*))?/?$ => index.php?&order-received=$matches[2]"
"view-order(/(.*))?/?$ => index.php?&view-order=$matches[2]"
"edit-account(/(.*))?/?$ => index.php?&edit-account=$matches[2]"
"edit-address(/(.*))?/?$ => index.php?&edit-address=$matches[2]"
"lost-password(/(.*))?/?$ => index.php?&lost-password=$matches[2]"
"customer-logout(/(.*))?/?$ => index.php?&customer-logout=$matches[2]"
"add-payment-method(/(.*))?/?$ => index.php?&add-payment-method=$matches[2]"
"comments/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]&withcomments=1"
"comments/(feed|rdf|rss|rss2|atom)/?$ => index.php?&feed=$matches[1]&withcomments=1"
"comments/wc-api(/(.*))?/?$ => index.php?&wc-api=$matches[2]"
"search/(.+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?s=$matches[1]&feed=$matches[2]"
"search/(.+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?s=$matches[1]&feed=$matches[2]"
"search/(.+)/page/?([0-9]{1,})/?$ => index.php?s=$matches[1]&paged=$matches[2]"
"search/(.+)/wc-api(/(.*))?/?$ => index.php?s=$matches[1]&wc-api=$matches[3]"
"search/(.+)/?$ => index.php?s=$matches[1]"
"author/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?author_name=$matches[1]&feed=$matches[2]"
"author/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?author_name=$matches[1]&feed=$matches[2]"
"author/([^/]+)/page/?([0-9]{1,})/?$ => index.php?author_name=$matches[1]&paged=$matches[2]"
"author/([^/]+)/wc-api(/(.*))?/?$ => index.php?author_name=$matches[1]&wc-api=$matches[3]"
"author/([^/]+)/?$ => index.php?author_name=$matches[1]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&feed=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&paged=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]&wc-api=$matches[5]"
"([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&day=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&feed=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]"
"([0-9]{4})/([0-9]{1,2})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&monthnum=$matches[2]&wc-api=$matches[4]"
"([0-9]{4})/([0-9]{1,2})/?$ => index.php?year=$matches[1]&monthnum=$matches[2]"
"([0-9]{4})/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&feed=$matches[2]"
"([0-9]{4})/(feed|rdf|rss|rss2|atom)/?$ => index.php?year=$matches[1]&feed=$matches[2]"
"([0-9]{4})/page/?([0-9]{1,})/?$ => index.php?year=$matches[1]&paged=$matches[2]"
"([0-9]{4})/wc-api(/(.*))?/?$ => index.php?year=$matches[1]&wc-api=$matches[3]"
"([0-9]{4})/?$ => index.php?year=$matches[1]"
"[^/]+/attachment/([^/]+)/?$ => index.php?attachment=$matches[1]"
"[^/]+/attachment/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
"[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"
"([^/]+)/trackback/?$ => index.php?name=$matches[1]&tb=1"
"([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?name=$matches[1]&feed=$matches[2]"
"([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?name=$matches[1]&feed=$matches[2]"
"([^/]+)/page/?([0-9]{1,})/?$ => index.php?name=$matches[1]&paged=$matches[2]"
"([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?name=$matches[1]&cpage=$matches[2]"
"([^/]+)/wc-api(/(.*))?/?$ => index.php?name=$matches[1]&wc-api=$matches[3]"
"[^/]+/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"[^/]+/attachment/([^/]+)/wc-api(/(.*))?/?$ => index.php?attachment=$matches[1]&wc-api=$matches[3]"
"([^/]+)(/[0-9]+)?/?$ => index.php?name=$matches[1]&page=$matches[2]"
"[^/]+/([^/]+)/?$ => index.php?attachment=$matches[1]"
"[^/]+/([^/]+)/trackback/?$ => index.php?attachment=$matches[1]&tb=1"
"[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ => index.php?attachment=$matches[1]&feed=$matches[2]"
"[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$ => index.php?attachment=$matches[1]&cpage=$matches[2]"

I fix the problem (temporarily) with some array_splice, but I believe this fix could break in the futur

I would want to know why the generation is wrong

Thank you very much

Related posts

Leave a Reply