RedirectMatch Examples: How to Use Apache RedirectMatch for Clean URL Redirects
TL;DR Summary: Apache users can efficiently redirect URLs based on patterns using RedirectMatch, which combines simplicity with the power of regular expressions. Real-world examples, explanations, and tips are provided, including when to use 301 vs 302 redirects. RedirectMatch is ideal for simple, flexible, pattern-based redirects without the complexity of full rewrite logic. Read more about RedirectMatch here.
If youโre working with Apache and need to redirect URLs based on patterns, RedirectMatch is your friend. It combines the simplicity of the Redirect directive with the power of regular expressions.
Below are real-world RedirectMatch examples you can use right nowโalong with explanations, tips, and answers to related questions like when to use 301 vs 302 and how redirects differ from rewrites.
Real RedirectMatch Examples (Copy and Paste Ready)
# Redirect a single page
RedirectMatch 301 ^/old-page$ /new-page
# Redirect everything under /blog/ to /articles/
RedirectMatch 301 ^/blog/(.*)$ /articles/$1
# Redirect /products or /products/ to /store/
RedirectMatch 301 ^/products/?$ /store/
# Temporary redirect
RedirectMatch 302 ^/temporary/?$ /new-temp/
# Complex pattern with two variables
RedirectMatch 301 ^/category/(.*)/item/(.*)$ /shop/$1/$2
301means permanent (good for SEO)302means temporary (used for short-term changes)- The pattern is a regular expression matched against the request URI
A Path vs. a URL
When using RedirectMatch in your .htaccess file, youโre matching the path portion of the URLโnot the full URL.
For example:
- Full URL:
https://example.com/old-page - Path:
/old-page
The regular expression in RedirectMatch is applied to just the path. So donโt include https:// or your domain in the match patternโonly what comes after the slash.
How to Use RedirectMatch
The syntax looks like this:
RedirectMatch [status] [regex pattern] [destination]For example:
RedirectMatch 301 ^/old-page$ /new-pageThis means: “Permanently redirect anyone visiting /old-page to /new-page.”
You can use regex groups like (.*) to match and re-use parts of the original URL in the destination path.
RedirectMatch vs Redirect vs RewriteRule
- Redirect: Simple, non-regex match. Great for single-page redirects.
- RedirectMatch: Uses regular expressions to handle multiple similar URLs with one line.
- RewriteRule: Used in
mod_rewrite, offers the most power (can do internal rewrites, add conditions, etc.)
Use RedirectMatch when you want simple but flexible pattern-based redirects without getting into full rewrite logic.
Understanding Regular Expressions in RedirectMatch
RedirectMatch uses regular expressions (regex) to match URLs. If youโve never used regex before, hereโs what you need to know – and “string” means a string of characters, or in this case, a URL usually:
^means โstart of the stringโ$means โend of the stringโ.matches any single character*means โzero or more of the previous characterโ(.*)matches everything between slashes (and saves it as a group you can reuse)$1, $2, etc.refer to matched groups in the destination URL?after a character makes it optional (e.g./?$matches with or without a trailing slash)
Example:
RedirectMatch 301 ^/blog/(.*)$ /articles/$1This means: โTake whatever comes after /blog/ and redirect it to /articles/ with that same slug.โ
So /blog/my-post becomes /articles/my-post.
If regex still feels confusing, start small. Even just knowing ^, $, and (.*) will get you 90% of the way there for basic redirect rules.
Free Download: Regular Expressions Cheat Sheet (PDF)
Here’s a cheat sheet you can download (no email required) to have as a handy reference for working with regular expressions and RedirectMatch.
How to Tell If a URL Is a Redirect
There are a few ways to check:
- Use the terminal:
curl -I https://example.com/old-page - Look for a
301or302status in browser dev tools (Network tab) - Use online tools like httpstatus.io to check live URLs
What to Put in a Redirect URL?
The destination URL can be:
- A relative path:
/new-page - A full URL:
https://example.com/new-page
Use relative paths for internal redirects. Use full URLs if redirecting to a different domain.
What Is Considered a Redirect?
A redirect is a response that tells the browser to go to a different URL. This can be:
- 301: Permanent redirect (good for SEO)
- 302: Temporary redirect
- 307/308: Special-purpose redirects
- Meta refresh: Client-side redirect via HTML (not recommended)
What Is a Redirect URL Example?
Hereโs a real example using RedirectMatch:
RedirectMatch 301 ^/blog$ /articlesThis redirects visitors from /blog to /articles. Simple and effective.
What Is an Open Redirect URL Example?
An open redirect allows external input to control the redirect destination. For example:
/go.php?url=https://badsite.comIf this page redirects users without validating the URL, it can be abused for phishing or malware. Always sanitize input and avoid generic redirect scripts unless they’re locked down.
What Is the Difference Between Redirect and Forwarding a URL?
- Redirect: The userโs browser is sent to a new URL (visible to them).
- Forward: The server fetches another page and shows it without changing the URL in the browser.
Use redirects for SEO and clear URL transitions. Use forwarding for behind-the-scenes routing (usually handled with RewriteRule).
What Is the Best Redirect Method?
For SEO and most use cases, a 301 redirect is best. It tells search engines the change is permanent and passes link authority. Use 302 for short-term moves or testing.
Avoid 307 or JavaScript-based redirects unless you have a specific reason. Stick with 301/302 for clean, reliable behavior.
Final Thoughts
If you manage an Apache-based website, RedirectMatch is one of the easiest ways to redirect groups of URLs using patterns. Itโs more powerful than Redirect, easier than RewriteRule, and perfect for SEO, content restructuring, or website cleanup.
Use it wisely, test thoroughly, and double-check your patterns. A good redirect saves SEO equityโa bad one can break your site.
And:
- Don’t forget to visit my Redirect Examples Using .htaccess page.
- If you like the copy buttons on this page, check out my WordPress Code Copy Button Plugin.
Got questions? Drop them below.
People Also Ask:
- redirectmatch examples
๐ Download a PDF of This Article

