Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#54654 new defect (bug)

Can flush_rewrite_rules() be called automatically after changing the site URL?

Reported by: pikamander2's profile pikamander2 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Rewrite Rules Keywords:
Focuses: Cc:

Description

A common issue that users run into after changing the WordPress Address and/or Site Address (such as when migrating to a new domain) is that some of their links stop working correctly after a site change.

The most common fix/workaround is to go to the wp-admin > Settings > Permalinks page and click "Save" once or twice, which usually does the trick.

Examples of this problem and workaround can be found all over Google:

https://www.google.com/search?q=wordpress+links+not+working+after+migration

https://wordpress.stackexchange.com/questions/221108/wordpress-links-not-working-after-migration

https://wordpress.stackexchange.com/questions/14685/after-server-migration-only-the-homepage-works

https://wordpress.stackexchange.com/questions/253245/wordpress-migration-getting-404-errors-only-home-page-works

https://stackoverflow.com/questions/42162570/wordpress-issue-after-migration-only-homepage-works

https://stackoverflow.com/questions/39514343/wordpress-migration-broken-links

I'm not sure if there's already a ticket for this anywhere, but surely there's some way to do this automatically? The view counters on the various Stack Exchange questions suggest that it has affected hundreds of thousands or even millions of users, so fixing it would be a fantastic QOL improvement, especially for non-technical users and users who don't notice the broken links until they start getting complaints.

Would it be possible to automatically flush_rewrite_rules() in the core function that handles the address change? I haven't looked into what happens when the permalink settings are resaved, but I would imagine that it does something similar there.

Change History (3)

#1 @costdev
3 years ago

I'm not sure why this issue is still experienced, but here's a couple of references:

See update_home_siteurl().
See when it's called.

#2 in reply to: ↑ description @SergeyBiryukov
3 years ago

  • Component changed from General to Rewrite Rules

Hi there, welcome back to WordPress Trac! Thanks for the ticket.

Replying to pikamander2:

Would it be possible to automatically flush_rewrite_rules() in the core function that handles the address change?

As noted above, this does in fact already happen since WordPress 1.5.1. Some history here:

  • [2494] If home changes, write rewrite rules to new location.
  • [3373] Cache rewrite rules. Add WP_Rewrite::flush_rules(). fixes #2155
  • [4175] Move home and siteurl update events to action hooks.

Some other tickets that might be related: #47526, #47686.

#3 @pikamander2
3 years ago

I've definitely had it happen in recent versions of WordPress, although I didn't pay close attention to the cause. If I can find a way to reproduce it without third-party plugins, I'll report it here.

Note: See TracTickets for help on using tickets.