Regex matching

By using regex matching, you can create infinite complex redirect rules.
Available from our Pro plan and up.

How to use

To enable a regex rule, add an exclamation mark (!) before your source URL.

!example.com/path/(.*)

This will tell the redirecting engine that the source's path contains a regex which should be matched against the incoming URL.

Example 1

You have developed a new website, and don't have a news page anymore. You wish to redirect all old news pages to a single URL called `https://new-website.com/news-is-removed`

You may define a regex rule like:

!example.com/news/(.*)

This will match all pages that start with `news/`, so you can redirect all paths to a single destination.

URLs that would match:
https://example.com/news/test-123
https://example.com/news/other-article/sub-page-as-well

URLs that wouldn't match:
https://example.com/other-page
https://example.com/news

Example 2

You have an old website that have paths that begin with `farming`, `machine` and `agriculture`. You then wish to redirect all paths that begin with `farming` or `machine`. To accomplish this, you can use a regex like stated below.

!example.com/[farming|machine]-.*

URLs that would match:
https://example.com/farming-page
https://example.com/machine-page/sub-path-as-well

URLs that wouldn't match:
https://example.com/agriculture-page
https://example.com/other-page

Capture groups

You may define capture groups in your regex to use in the destination. The captured group will be passed along to variables like `$1`, `$2` etc. (up to `$10`).

Example 1:

The following example is a simple capture group. We match all paths after the 'welcome/' path, and pass along that part to the destination via the variable `$1`

!example.com/welcome/(.*)/

Then, you may use the capture group's result with the `$1` variable:

https://destination.com/$1

Example 2:

The following example matches the URL if it starts with a valid year-month-day format, with a slug next to it. We then want to pass the date & slug to the new destination, but with a slash as a seperator.

!example.com/^(\d{4}-\d{2}-\d{2})?\/([\w-]+)$

URLs that would match:
https://example.com/2023-01-01/article-slug
https://example.com/2022-06-02/another-article

URLs that wouldn't match:
https://example.com/2023/article-slug
https://example.com/article-slug
https://example.com/20230101/article-slug
https://example.com/202301/article-slug
https://example.com/2023-01-01/article-slug/extra-slug

Then, you may use the two captured groups in the destination how you prefer to build up the new URL:

https://destination.com/news/$1-$2

The destination would be build up with the full date and a dash between the slug. Example: https://destination.com/news/2023-01-01-article-slug

Regex engine

Regexes are matched with the Go/RE2 engine. Reference material can be found here.

Matching order

When multiple regex rules are defined under a singular source, the matching order follows a specific priority logic:

  • First, we count how many unique segments are in the source path. These are defined by the number of slashes. We don't count slashes within regex capture groups.
  • The rule with the highest number of segments (i.e. the deepest path) is tried first, then the second etc.
  • If multiple rules have the same number of segments, then we sort by the length of the path—longer paths are tried before shorter ones.

This system ensures that the most specific and deeply nested regex rules are matched before broader, more general ones.

Testing

We recommend the following tool to match your regex against your path examples:
https://regex101.com(make sure you select the Golang flavor)

Closing

Do note that the examples above are only indicative examples. Regex matching is extremely powerful and can basically be useful for any path redirect.

More articles

Walkthroughs
GoDaddy: Forwarding with HTTPS support
Network Solutions: Forwarding with HTTPS support
Namecheap: Forwarding with HTTPS support
Hover: Forwarding with HTTPS support
TransIP: Forwarding with HTTPS support
Cloudflare: Forwarding with HTTPS support
Amazon Route 53: Forwarding with HTTPS support
NS1: Forwarding with HTTPS support
DigitalOcean: Forwarding with HTTPS support
Google Cloud DNS: Forwarding with HTTPS support
EuroDNS: Forwarding with HTTPS support
Azure DNS: Forwarding with HTTPS support
DNS Made Easy: Forwarding with HTTPS support
Freenom: Forwarding with HTTPS support
Mijndomein: Forwarding with HTTPS support

Domain redirects delivered hassle-free

Get started right away

  • Free plan
  • No creditcard required

redirect.pizza has all your favorite ingredients

Analytics

Who is still visiting those old domains? Gain valuable insight with detailed statistics and find out where the hits are coming from.

Learn more

API

Connect your software to automatically create redirects via our API. Automation makes your life easier.

Learn more

Destination Variables

You control how we handle your destination URL. Want to include your domain extension as a query string parameter? No problem.

Learn more

Dynamic destinations

Steer your traffic to different destinations, based on rules you define.

Learn more

Path forwarding

Keep the original path and keep it in the destination for a smooth domain migration and keeping your SEO game intact.

Learn more

Query Parameter Forwarding

Forward query parameters found on the source URL to the destination.

Learn more

Multiple Redirect Types

Choose the status code that works for you. Choose 301/307 (permanent), 302/308 (temporary) or frame your destination.

Learn more

Team management

Doing things all by yourself isn't much fun. Invite your co-workers to manage the redirects and work as a team.

Learn more

Automatic DNS

Integrate directly with your DNS provider, and apply the DNS changes from one platform.

Learn more

QR code generator

Create a QR code that you can use for marketing purposes. You can change the destination anytime after printing.

Learn more

Import & Export

Manage your redirects without losing precious time. Import and export redirects in our UX-friendly interface.

Global edge network

Redirecting in a blink of an eye; processing millions of request per hour in milliseconds.

Learn more

Broken destination monitor

Automatically checking your destinations to ensure it's reachable for everyone.

Learn more

Privacy First

We're based in Europe and are fully compliant with GDPR. Privacy-first!

Learn more

Wildcard subdomains

For when your domain utilizes a lot of different subdomains. Cover all subdomains with a single redirect.

Learn more

Tags

Group your redirects by adding tags. Keep everything organized and easy to find.

Bulk actions

Want to apply the same action for multiple redirects in one go? Do yourself a favor and start using bulk actions.

Dark mode

Give your eyes some well deserved rest by using the dark mode. Sync with your system or choose manually.

HSTS

Enable HSTS (HTTP Strict Transport Security) on team or domain level for an extra layer of protection.

Learn more

Change Destination Anytime

Once you're set up, you can change the destination URL anytime you want, and see the change in real-time.

Two-Factor Authentication

Secure your account with TOTP two-factor authentication. Scan the QR code, setup your app of choice, and you're safe(er).

Learn more

IDN Support

Add international hostnames with non-Latin characters. We ❤ that.

Support

Chat away! We're happy to help set up your account and answer your questions.