What is Wildcard Redirect in .htaccess, Nginx, and cPanel – Step-by-Step Guide
A wildcard redirect is one of the most useful tools for website owners when managing domain changes, migrations, or URL restructuring. Instead of redirecting each page individually, a wildcard redirect allows you to forward an entire set of URLs from one location to another with a single rule.
To understand it better, let’s start with the basics. A redirect is simply a way of sending both users and search engines from an old URL to a new one. For example, if you move your blog from olddomain.com/blog to newdomain.com/articles, a redirect makes sure visitors don’t land on a broken page.
Now, the wildcard redirect comes into play when you want to apply this rule to all pages under a folder or domain. This means that every URL, such as olddomain.com/blog/post1 or olddomain.com/blog/post2, can be automatically redirected to the matching URL under newdomain.com/articles/* without requiring separate redirects for each one.
This is extremely valuable for SEO and user experience. It helps preserve your search rankings, prevents 404 errors, and ensures all your backlinks remain useful.
Whether you’re moving to a new domain, cleaning up your site structure, or consolidating multiple websites, wildcard redirects save time and protect your site’s performance.
What is a Wildcard Redirect?
A wildcard redirect is a type of redirect that forwards all the URLs of a domain or subdomain to another domain or subdomain. Instead of setting up redirects one by one for each page, you can use a wildcard to handle every URL under that path in a single rule.
For example, if you set up a wildcard redirect from oldsite.com/* to newsite.com/*, every page from your old site, like oldsite.com/about, oldsite.com/blog/post1, or oldsite.com/contact, will automatically point to the matching page on your new site.
Now, how is this different from a regular redirect?
- A regular redirect is set up for one specific URL. For example, oldsite.com/about → newsite.com/about.
- A wildcard redirect, on the other hand, applies to an entire domain, folder, or subdomain in one go. It’s like creating a blanket rule that covers all cases at once.
This makes wildcard redirects extremely useful in real-world scenarios. Common use cases include:
- Moving from one domain to another (e.g., olddomain.com/* → newdomain.com/*).
- Redirecting a subdomain to the main site (e.g., blog.oldsite.com/* → oldsite.com/blog/*).
- Cleaning up or restructuring URLs after a website migration.
In short, a wildcard redirect is a powerful shortcut that saves time, avoids errors, and ensures visitors always find the right page.
Why Use a Wildcard Redirect?
There are many situations where a wildcard redirect can save you time and prevent problems. Let’s look at some of the most common reasons:
Domain migration (moving the entire website)
When you move your site to a new domain, you don’t want visitors or search engines landing on broken pages.
A wildcard redirect makes sure every URL from the old domain automatically points to the same path on the new one. This way, your whole website moves smoothly without needing hundreds of separate rules.
Changing from HTTP to HTTPS
Switching from http:// to https:// is a must for security and trust. Instead of creating individual redirects, a wildcard redirect ensures that all your pages are forced to load over HTTPS. This not only protects your site but also gives a ranking boost in Google.
Sometimes, websites start with content on subdomains like blog.domain.com or shop.domain.com. Later, you may want to merge them into your main site structure, like domain.com/blog.
A wildcard redirect makes this easy, sending all subdomain URLs to the correct folder without manual work.
Preserving SEO value with 301 redirects
Search engines rely on redirects to understand when a page has moved. A 301 wildcard redirect tells Google that your content has permanently shifted, passing most of the SEO value and backlinks to the new location. This is crucial for keeping your rankings intact after a big change.
User experience improvements
At the end of the day, redirects are about people. No one likes hitting a 404 error. With wildcard redirects, your visitors always land on the right page, even if they typed in an old link, clicked an outdated bookmark, or followed a backlink. This smooth experience builds trust and keeps users engaged.
Types of Wildcard Redirects
Not all wildcard redirects are the same. Depending on your goal, you can choose between different types of redirects. Here are the most common ones:
301 Wildcard Redirect (Permanent)
A 301 wildcard redirect tells browsers and search engines that a page or an entire set of URLs has moved permanently. This is the most SEO-friendly option because it passes most of the link equity (ranking power) from the old URLs to the new ones.
If you’re migrating to a new domain or changing your site structure for good, this is the type of redirect you should use. It helps preserve your search rankings while keeping your visitors happy.
302 Wildcard Redirect (Temporary)
A 302 wildcard redirect is used when the change is only for a short period of time. For example, if you’re testing a new site layout or running a temporary campaign, you might redirect traffic with a 302.
Unlike 301, it doesn’t pass full SEO value, because it signals to search engines that the original page will come back. Once you’re done testing, you should switch back or set up a proper 301.
Subdomain Wildcard Redirects
Sometimes, you may want to forward all traffic from a subdomain to your main site or another section of your site. For example, blog.example.com/* could be redirected to example.com/blog/*.
This is useful when you’re consolidating content or restructuring your website. Instead of writing redirects for each blog post or product page, one wildcard rule can handle the entire subdomain.
How to Set Up a Wildcard Redirect (Step-by-Step)
Below, I’ll walk you through practical, copy-paste-ready examples for .htaccess (Apache), Nginx, and cPanel. Each example preserves the path (the /* part), so olddomain.com/some/page becomes newdomain.com/some/page. I’ll explain what each line does and give quick troubleshooting tips.
1. Wildcard Redirect in .htaccess (Apache)
Redirect all pages from one domain to another (preserve path)
Put this in the root .htaccess of the old domain:
# Turn on rewrite engine
RewriteEngine On
# Match olddomain.com with or without www
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
# Redirect everything to the new domain, preserving the path and query string
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
What each line does:
- RewriteEngine On — enables mod_rewrite rules.
- RewriteCond — only apply the rule if the request is for olddomain.com (with or without www).
- RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L] — capture the whole requested path ($1) and append it to the destination; R=301 makes it permanent (SEO-friendly).
Simpler alternative with RedirectMatch
If your host supports RedirectMatch, this shorter rule also preserves paths:
RedirectMatch 301 ^/(.*)$ https://newdomain.com/$1
Redirecting HTTP → HTTPS for the same domain
To force https while keeping the path, add this (in the old site root .htaccess):
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
This checks if the connection is not HTTPS and then redirects to the same host over HTTPS while preserving the path and query. Test after uploading with curl -I http://olddomain.com/somepage.
Notes/troubleshooting
- Put .htaccess in the site root. If rules don’t work, confirm AllowOverride is enabled and mod_rewrite is available on the server.
- Always back up your .htaccess work before editing.
2. Wildcard Redirect in Nginx
Nginx handles redirects in the server block (site config), not .htaccess. The simplest, fastest way is to use return.
Redirect all traffic from old domain → new domain (preserve path)
Add a server block like this (usually in /etc/nginx/sites-available/):
server {
listen 80;
server_name olddomain.com www.olddomain.com;
# Preserve full request URI (path + query string)
return 301 https://newdomain.com$request_uri;
}
Why this works:
- server_name lists the old domains to match.
- return 301 https://newdomain.com$request_uri; performs a permanent redirect, appending the original path and query ($request_uri). This is the recommended, efficient approach.
Redirect a subdomain to a folder (example: blog.olddomain.com/* → olddomain.com/blog/*)
server {
listen 80;
server_name blog.olddomain.com;
# Redirect all blog subdomain requests to main site's /blog path
return 301 https://olddomain.com/blog$request_uri;
}
Redirect HTTP → HTTPS globally
You can redirect all HTTP requests to HTTPS (same domain) like this:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
Notes/troubleshooting
- After editing, test config: nginx -t and then reload systemctl reload nginx.
- Use return for simple redirects — it’s faster and clearer than rewrite for this use case.
3. Wildcard Redirect in cPanel
If you’re on shared hosting with cPanel, the UI makes this easy, no manual code needed. The screenshots at the top show the cPanel Redirects interface (I included examples). The official cPanel docs also explain the Wild Card Redirect option.
Step-by-step (GUI)
- Log in to cPanel.
- Go to Domains → Redirects (or search “Redirects” in the cPanel dashboard).
- Choose redirect type: Permanent (301) for SEO-friendly moves, or Temporary (302) if short-term.
- In the domain dropdown, choose the domain you want to redirect (or enter the path if you’re redirecting a specific folder).
- In Redirects to, enter the new destination (include https:// if you want HTTPS.
- Important: Tick Wild Card Redirect to append the old path to the new URL (/oldpage → /oldpag on the new site. Then click Add.
What the Wild Card checkbox does
When Wild Card Redirect is enabled, cPanel maps files and paths automatically. For example, olddomain.com/images/pic.jpg → newdomain.com/images/pic.jpg without extra rules. This is the exact UI behavior documented by cPanel.
Notes/troubleshooting
- You cannot edit an existing redirect; you must delete and recreate it if you need to change it.
- After adding, test a few URLs (home page + a couple of inner pages) and check the response headers with curl -I to confirm 301 and Location: are correct.
Quick testing checklist (final)
- Clear browser cache or use an incognito window.
- Test with curl -I https://olddomain.com/some/page and confirm HTTP/1.1 301 Moved Permanently and Location: https://newdomain.com/some/page.
- After major changes, monitor Google Search Console for indexing changes and crawl errors.
Wildcard Redirect Examples
Sometimes it’s easier to understand wildcard redirects by looking at real examples. Here are a few common scenarios:
Redirecting from HTTP to HTTPS
Let’s say your old site was running on http:// and now you’ve installed SSL. A wildcard redirect makes sure every page automatically loads with https://.
- Example: http://olddomain.com/page → https://newdomain.com/page.
This way, no matter which page someone visits, they’ll always land on the secure version.
Redirecting a subdomain to a folder
Many websites start with a blog on a subdomain, like blog.old.com. Later, they move it into a folder on the main domain. Instead of setting up redirects for each post, a wildcard redirect handles it all.
- Example: blog.old.com/* → old.com/blog/*.
So, blog.old.com/post1 becomes old.com/blog/post1, and the same rule applies to every post.
Redirecting all traffic to one page
Sometimes you don’t want to preserve the exact path. Instead, you may want all visitors from an old domain or section to land on a single page.
- Example: olddomain.com/* → newdomain.com/landing-page.
This is useful if you’re running a campaign, retiring a website, or consolidating everything into one page.
SEO Benefits of Wildcard Redirects
One of the biggest reasons to set up wildcard redirects is the SEO value they bring. If not handled properly, a domain change or site migration can cost you rankings, traffic, and authority. Wildcard redirects help you avoid these problems.
Preserves link juice during migrations
When you move your site to a new domain or restructure URLs, you don’t want to lose the SEO power of your existing backlinks. A 301 wildcard redirect passes most of that “link juice” to the new URLs, helping your new site maintain its rankings.
Prevents broken links (404 errors)
Broken links are frustrating for users and harmful for SEO. If Google keeps finding 404 errors, it may stop crawling those URLs. Wildcard redirects ensure that visitors and search engines always land on a live page, even if they’re using old links.
Improves crawlability and indexing
Search engines need clear signals to understand your website. A wildcard redirect tells Google exactly where the content has moved. Instead of wasting crawl budget on non-existent pages, Googlebot can quickly find and index the right URLs.
Helps consolidate domain authority
Sometimes, businesses run multiple domains or subdomains. This can split your SEO strength. By using wildcard redirects, you can consolidate all that authority into one main domain, giving it more weight in search results.
In short, wildcard redirects are not just a technical fix; they’re a smart SEO move that protects your rankings and strengthens your site’s overall performance.
Common Mistakes & How to Avoid Them
Even though wildcard redirects are powerful, it’s easy to make mistakes that hurt your website’s performance or SEO. Here are some common issues and how to fix them:
Using 302 instead of 301
A 302 redirect tells search engines the move is temporary, so they don’t transfer SEO value to the new URL. If your site has permanently moved, always use a 301 redirect. This ensures that link equity (or “link juice”) passes to the new domain and your rankings stay intact.
Infinite redirect loops
Sometimes, redirects are set up incorrectly and end up pointing back to each other. For example, domain.com/* redirects to www.domain.com/*, but then another rule sends it back to domain.com/*. This creates a loop where the page never loads.
To avoid this, always test your redirects with tools like curl -I or online redirect checkers to make sure they end in a valid destination.
Forgetting the HTTPS setup
If you’ve switched to HTTPS but only redirected your old domain, visitors may still access insecure pages. This not only confuses but also raises security warnings in browsers. Make sure you add a wildcard redirect from HTTP to HTTPS so every page automatically loads securely.
Incorrect wildcard patterns
Wildcard rules need to be written carefully. A small mistake, like missing a $1 or using the wrong syntax, can break your redirects or send all traffic to the wrong page.
Always double-check your code, and if possible, test it on a staging server before applying it to your live site.
By avoiding these mistakes, you’ll keep your redirects clean, SEO-friendly, and user-friendly.
Alternatives to Wildcard Redirects
While wildcard redirects are powerful and convenient, they’re not the only way to handle URL changes. Depending on your situation, you might find one of these alternatives more suitable:
Regex-based redirects
Regular expressions (regex) give you more control than simple wildcards. With regex, you can set very specific patterns, like redirecting only certain folders, file types, or URL structures.
For example, you could redirect only URLs ending in .php to their new .html versions. Regex takes more effort to learn, but it’s flexible and powerful if you need advanced rules.
Page-by-page manual redirects
If you only have a small number of pages to redirect, you might not need a wildcard rule at all. Instead, you can set up redirects manually, one by one.
For example:
- /about → /about-us
- /services → /our-services
This method is slower for large sites, but it gives you complete control over where each old page points.
Using CMS plugins (WordPress redirect plugins)
If your site runs on WordPress or another CMS, you don’t always need to touch server files. Plugins like Redirection, Yoast SEO Premium, or Rank Math let you set up both simple and wildcard-style redirects right from the dashboard.
This is often easier for beginners since you don’t have to edit .htaccess or server configs. Just install the plugin, add your redirect rules, and you’re good to go.
FAQs Related to Wildcard Redirect
What is a wildcard redirect?
A wildcard redirect is a rule that forwards all URLs from one domain, subdomain, or folder to another location. It saves time by handling multiple pages with a single redirect.
How do I set up a 301 wildcard redirect?
You can add a 301 wildcard redirect in .htaccess (Apache), your Nginx config, or through cPanel’s redirect option. A 301 tells search engines the move is permanent.
Does wildcard redirect affect SEO?
Yes, but in a good way. A 301 wildcard redirect passes most of the SEO value (link juice) to the new URLs, helping you preserve rankings during a migration.
How do I redirect a subdomain using a wildcard?
You can point a subdomain blog.old.com/* to old.com/blog/* using a wildcard rule in .htaccess, Nginx, or cPanel. This redirects all subdomain pages to the correct folder.
Can I use a wildcard redirect in WordPress?
Yes. You can either edit your .htaccess file manually or use WordPress plugins like Redirection or Rank Math to set up wildcard redirects without touching server code.
What is the difference between a wildcard and a regex redirect?
A wildcard redirect is simpler and matches everything under a domain or folder. Regex (regular expressions) gives you more control and allows complex redirect patterns, like targeting only certain file types or keywords.
Conclusion
Wildcard redirects may look technical at first, but they solve one of the most common problems in website management, making sure visitors and search engines always reach the right page.
Whether you’re moving to a new domain, switching to HTTPS, or restructuring your site, a wildcard redirect saves time and prevents broken links.
When it comes to SEO, the safest choice is always a 301 wildcard redirect. This tells Google and other search engines that the move is permanent and ensures your backlinks, rankings, and domain authority carry over to the new URLs.
Using 302 redirects for permanent moves can cost you valuable SEO power, so avoid that mistake.
Finally, follow best practices whenever you set up wildcard redirects. Test them before going live, watch out for redirect loops, and monitor your site in Google Search Console to catch any errors quickly.
If you’re using WordPress or cPanel, don’t hesitate to use plugins or built-in tools, they make the process much easier.
Handled the right way, wildcard redirects not only protect your SEO but also give visitors a smooth, hassle-free browsing experience. That’s a win for both your website and your audience.
