-
Notifications
You must be signed in to change notification settings - Fork 16
Home
With the WPCOM Legacy Redirector plugin, site managers can create redirects for old, or legacy, URLs that now return 404 HTTP response status codes.
Redirect data can be stored in a CSV file OR in a post meta field. With the post meta field method, the resulting redirect is then attached to an existing post (and follows the post through future updates) whereas, with the CSV method, the redirect is attached to a hardcoded URL.
During plugin installation, be sure to download the plugin files from the develop
branch
This plugin will not redirect valid URLs. If the URL does not return a 404, the redirect will not trigger, which means it won’t redirect live pages.
If a slug should be a 404 but matches the start of another slug, WordPress will return that instead and the redirect will not trigger.
All redirect bulk-loading needs to be done via WP-CLI commands.
If you have questions about how this plugin will work on your site or if you’d like to have us review your redirect strategy, please contact us before using this plugin.
Redirects are stored as a custom post type and use the following fields:
-
post_name
for the md5 hash of the "from" path or URL.- we use this column, since it's indexed and queries are super fast.
- we also use an md5 just to simplify the storage.
-
post_title
to store the non-md5 version of the "from" path. - one of either:
-
post_parent
if we're redirect to a post; or -
post_excerpt
if we're redirecting to an alternate URL.
-
There are three ways to create redirects:
1. Adding redirects from WordPress Admin Visit the Redirect Manager → Add Redirect WP Admin screen and add redirects individually.
2. Adding redirects from a CSV file This method is recommended for bulk import redirects.
Create a .csv
file and format the redirect URLs with one of the following mapping structures:
-
Relative Path:
/redirect_from/,/redirect_to
-
Post ID:
/redirect_from/,123(redirect_to_post_id)
-
URL:
/redirect_from/,https://site.com(redirect_to_url)
All of the methods above require that redirect_from
values contain a beginning slash (/
) and trailing slash (/
).
Follow these instructions to add the redirect: https://github.com/Automattic/WPCOM-Legacy-Redirector/wiki/Adding-Redirects-from-a-CSV-File
3. Adding Redirects from Post Meta Fields This method creates a redirect from the address found in the meta field to the post that has the meta field.
Follow these instructions to add the redirect: https://github.com/Automattic/WPCOM-Legacy-Redirector/wiki/Adding-Redirects-from-Post-Meta-Fields