A “Regular Expression,” or RegEx, is a set of characters that create a search pattern. RegEx is useful for redirects because it allows you to dynamically match any number of URLs without creating a specific rule for each, even without knowing what those URLs might all be.
Regex Pal
Regex Syntax Breakdown
Regular Expressions Info
RegEx 101
Character | Definition |
^ | Match only if the characters following are at the beginning |
$ | Match only if the characters before are at the end |
? | The character just before this is optional |
(?i) | All following characters are case-insensitive |
. | Any 1 character |
* | Match the previous character 0 or more times |
+ | Match the previous 1 or more times |
(x) | Capture group. The characters inside are called by a variable later. Variables are numerical such as $1 |
.* | A wildcard; any letter, word, or phrase |
.+ | Similar to a wildcard but requires at least 1 character to be present to continue |
(?!) | Negative lookahead, the following characters are excluded |
Escape reserved character, so it functions as alphanumeric instead, goes just before each reserved character |
Any RegEx functional character is not assumed to be read as alphanumeric, but rather as its function in RegEx.
For example, this is relevant when trying to redirect static assets which would include a period before the file extension. That period must be escaped with a backslash just before the period to say “read the next character as alphanumeric instead of as RegEx”.
Alphanumeric | RegEx |
image.png | image.png |
The space character must be escaped with a backslash proceeding the space character as well.
Alphanumeric | RegEx |
example phrase | example phrase |
Interpretation | Source RegEx | Destination |
Redirect from page1 to page2 | ^/page1/?$ | https://example.com/page2/ |
Redirect only part of the path | ^/old/page/?$ | https://example.com/new/page/ |
Redirect to a new starting path, while carrying over anything that follows. Matches root page request as well as any following arguments. | ^/old/(.*) | https://example.com/new/$1 |
Redirect to a new starting path, while carrying over anything that follows. Requires a following argument. | ^/old/(.+) | https://example.com/new/$1 |
Capture and reuse multiple pieces of the previous path in new destination | ^/old/(.+)/diff/(.+) | https://example.com/new/$1/other/$2 |
Redirect a static asset, such as a PDF file | ^/old/page\.pdf | https://example.com/new/page.pdf |
Redirect all pages to a subdirectory, and append the page to the URL using a capture group | ^/(.*)?$ | https://example.com/somedirectory/$1 |
If you have any questions our Happiness Engineers are here to help!
New to Flywheel? Start here, we've got all the information you'll need to get started and launch your first site!
View allLearn all about managing your Flywheel user account, Teams and integrations.
View allFlywheel hosting plans include a ton of great features. Learn about how to get a free SSL certificate, set up a staging site, and more!
View allAll the server and setting info you'll need to help you get the most out of your Flywheel hosting plan!
View allTips and tricks for managing your sites on Flywheel, including going live, troubleshooting issues and migrating or cloning sites.
View allLearn more about Growth Suite, our all-in-one solution for freelancers and agencies to grow more quickly and predictably.
Getting started with Growth Suite
Growth Suite: What are invoice statuses?
Growth Suite: What do client emails look like?
Learn more about Managed Plugin Updates, and how you can keep your sites up to date, and extra safe.
Restoring Plugin and Theme Management on Flywheel
Managed Plugin Updates: Database upgrades
Managed Plugin Updates: Pause plugin updates
We can help! Check out our Brand Resources page for links to all of our brand assets.
Brand Resources