How to Fix Redirection Issues with Regular Expressions and Wildcards
Content
If you're using the Redirection plugin and finding that your redirects aren't working as expected—perhaps they're appending extra parts of the URL or not capturing the patterns you need—you're not alone. This is a common hurdle, especially when moving sites or changing URL structures. This guide will walk you through the most frequent causes and their solutions.
The Core Problem: Understanding Regular Expressions
The most prevalent issue, as seen in numerous support threads, is a misunderstanding of how to use regular expressions (regex) for wildcard matching. A standard redirect without regex will perform a simple, literal match. To capture dynamic parts of a URL (like a changing post slug), you must use regex.
Common Scenario 1: Redirecting an Entire Directory
Problem: You want to redirect all URLs under an old directory (e.g., /trends/) to a single new page (e.g., /events/), but the redirect is incorrectly appending the old page slug to the new URL, sending users to a 404 page.
Incorrect Setup:
Source: /trends(.*)
Target: /events
Solution:
You must use a regex capture group and then ignore it in the target. Enable the "Regex" checkbox and use this structure:
Source: /trends/(.*)
Target: /events/
Note the trailing slash in the target. The (.*) captures any text after /trends/, but since you don't reference it (e.g., with $1) in the target, it is discarded.
Common Scenario 2: Changing URL Structures (e.g., Removing Categories)
Problem: You've changed your permalink structure to remove a category base (e.g., changing from /category/post-name/ to /post-name/) and need to redirect all old URLs.
Solution:
This is an ideal use case for the "Permalink Migration" feature built into Redirection.
- Go to Redirection > Options > Site.
- In the "Permalink Migration" section, enter your old permalink structure. For example, to remove
/category, you might enter/category/%postname%. - Save the changes. The plugin will now automatically handle redirects from the old structure to the new one without manually creating hundreds of rules.
Common Scenario 3: Redirects Not Firing for External Domains or Subdomains
Problem: You are trying to redirect a URL from an entirely different domain (e.g., blog.old.com) or a subdomain to your main WordPress site, but the plugin's source field only accepts relative paths.
Solution:
The Redirection plugin primarily manages redirects for its installed domain. To redirect from a different domain, you typically need to implement the redirect on the server hosting that original domain. For subdomains of the same domain, you can sometimes use the "URL and Server" match type. In the redirect rule, set the "Source" to the path and the "Match" type to "URL and Server." Then, you can specify the subdomain in the server field.
Why Your Redirect Might Still Not Work
If you've configured your regex correctly but the redirect isn't triggering, consider these other factors:
- Caching: A stubborn page or browser cache might be serving the old, broken page. Clear your site's cache and your browser cache before testing again.
- Conflicting Rules: A more specific redirect rule might be taking precedence over your new, broader rule. Review your list of redirects for any conflicts.
- Server Configuration: For redirecting files outside of the WordPress installation (like PDFs in an old server directory), server-level restrictions or other software (like security plugins on the server) can sometimes interfere. The Redirection plugin requires that the request is first processed by WordPress for it to act.
By methodically checking your regular expressions and understanding the scope of what the plugin can handle, you can resolve most redirection issues and ensure a smooth experience for your visitors and SEO.
Related Support Threads Support
-
How to redirect url with year and date to just post name in wordpress?https://wordpress.org/support/topic/how-to-redirect-url-with-year-and-date-to-just-post-name-in-wordpress-2/
-
Migrating from Wixhttps://wordpress.org/support/topic/migrating-from-wix/
-
Redirection from full URLhttps://wordpress.org/support/topic/redirection-from-full-url/
-
Possible to remove category from blog URLs and use wildcards?https://wordpress.org/support/topic/possible-to-remove-category-from-blog-urls-and-use-wildcards/
-
Rule after change of wp-content folderhttps://wordpress.org/support/topic/rule-after-change-of-wp-content-folder/
-
Redirect of a wp-content filehttps://wordpress.org/support/topic/redirect-of-a-wp-content-file/
-
Redirect on custom post deletionhttps://wordpress.org/support/topic/redirect-on-custom-post-deletion/
-
How to 301 redirect sub domain post URLS wordpress to root domainhttps://wordpress.org/support/topic/how-to-301-redirect-sub-domain-post-urls-wordpress-to-root-domain/
-
Redirecting from External Sitehttps://wordpress.org/support/topic/redirecting-from-external-site/
-
www. to non-wwwhttps://wordpress.org/support/topic/www-to-non-www-3/
-
Add/Remove redirects programmaticallyhttps://wordpress.org/support/topic/add-remove-redirects-programmatically/
-
RENEW SITEhttps://wordpress.org/support/topic/renew-site/
-
Redirect from URL Post no Category to URL Post inlcude Category inside posthttps://wordpress.org/support/topic/redirect-from-url-post-no-category-to-url-post-inlcude-category-inside-post-2/
-
Redirect all contents of a folderhttps://wordpress.org/support/topic/redirect-all-contents-of-a-folder/
-
Redirect sub-domain Pageshttps://wordpress.org/support/topic/redirect-sub-domain-pages/
-
Show message when redirected?https://wordpress.org/support/topic/show-message-when-redirected/
-
Redirect all post to /blog subfolderhttps://wordpress.org/support/topic/redirect-all-post-to-blog-subfolder/
-
Redirect asp pageshttps://wordpress.org/support/topic/redirect-asp-pages/
-
Redirect whole renamed directoryhttps://wordpress.org/support/topic/redirect-whole-renamed-directory/
-
Redirect external domain to wordpress sitehttps://wordpress.org/support/topic/redirect-external-domain-to-wordpress-site/
-
Redirect PDF outside of WordPresshttps://wordpress.org/support/topic/redirect-pdf-outside-of-wordpress/
-
Redirection gone badhttps://wordpress.org/support/topic/redirection-gone-bad/
-
html support ?https://wordpress.org/support/topic/html-support-6/
-
Feature request: set a default prefix for destination URLhttps://wordpress.org/support/topic/feature-request-set-a-default-prefix-for-destination-url/
-
no redirection happeninghttps://wordpress.org/support/topic/no-redirection-happening/
-
Redirection Timehttps://wordpress.org/support/topic/redirection-time/
-
SEO driven url changes site widehttps://wordpress.org/support/topic/seo-driven-url-changes-site-wide/
-
287,000+ 301 Redirectshttps://wordpress.org/support/topic/287000-redirects/
-
redirect change category part of URLhttps://wordpress.org/support/topic/redirect-change-category-part-of-url/
-
Redirecting Blog Site to Blog Pagehttps://wordpress.org/support/topic/redirecting-blog-site-to-blog-page/
-
Redirecting member URLshttps://wordpress.org/support/topic/redirecting-member-urls/
-
Redirect all post only to new locationhttps://wordpress.org/support/topic/redirect-all-post-only-to-new-location/
-
Redirect From Drupal Site to WPhttps://wordpress.org/support/topic/redirect-from-drupal-site-to-wp/
-
Redirect Deleted Listingshttps://wordpress.org/support/topic/redirect-deleted-listings/
-
Automating link directs after switching from old CMShttps://wordpress.org/support/topic/automating-link-directs-after-switching-from-old-cms/
-
Redirect using database informationhttps://wordpress.org/support/topic/redirect-using-database-information/
-
change ?lang=xx to /lang/https://wordpress.org/support/topic/change-langxx-to-lang-2/
-
Redirect postname to category/postnamehttps://wordpress.org/support/topic/redirect-postname-to-category-postname/
-
Redirecting Content on Subdomain (HubSpot) to Content on Root Domain (WordPress)https://wordpress.org/support/topic/redirecting-content-on-subdomain-hubspot-to-content-on-root-domain-wordpress/