Rewrite Content URLs
This plugin allows you to rewrite URLs in content.
This plugin was primarily designed for developers, useful for development/staging environments after syncing data from a MySQL dump.
DO NOT USE IN PRODUCTION: This plugin should only be used for development/staging sites with frequently-synced data, as it creates a performance penalty.
📌 Use in conjunction with: Network Sub-domain Updater for WordPress multisite
- WordPress 4.5 or higher
- PHP 7.0 or higher
output-buffering.php must be copied to your WordPress
This plugin will not work on versions of PHP below 7.0.
- Download and unzip the plugin to your WordPress plugins directory.
wp-config.phpfor your site and define the
- Activate the plugin.
There is no settings page in WP Admin for this plugin. All options are configured through
In order for this plugin to work, you must add a
REWRITE_URL_PATTERNS constant to your
Example of simply replacing the page links’ domain:
define( 'REWRITE_URL_PATTERNS', [ '/mydomain.com/' => 'mydomain.local' ] );
Example of simply replacing the page links’ domain AND stripping ‘www’ (useful if your local development stack doesn’t alias it):
define( 'REWRITE_URL_PATTERNS', [ '/(www.)?mydomain.com/' => 'mydomain.local' ] );
Since the constant expects an array, you and add multiple match expressions.
Let’s say you run a WordPress Network of sub-domains. If you did a MySQL dump from your production server (example.com) and then imported to your staging (staging.example.com) or local development (example.local) instance and updated the domains, the links in your page content will be pointing to the production site.
This plugin replaces URL patterns in content, defined by
For example, I use Local by Flywheel for local WordPress development:
- Create a local WordPress multisite instance.
- Copy necessary file assets (plugins, themes, uploads, etc) from the remote site.
- Install this plugin on your staging or development instance (not on production!)
Now when you view pages on your instance, the links will be rewritten to your new domain.
Frequently Asked Questions
Q: Why did you use a constant to define the replacement URLs and not a settings page in WP Admin?
A: This plugin was designed for developers who sync data via a MySQL dump from a production site to staging/local development. Because of this, any settings set in WP Admin would be blown away.
- Ability to rewrite image URLs
- Ability to set filter exceptions
- Possibility of moving configuration to file
Release changes are noted on the Releases page.
- None since release