Wildcard redirects allow you to redirect all URLs to a certain folder on your website. However, there are times when relocating your website is unavoidable. For example, this might result from redesigning, rebranding, or traffic redirection to new content.
Table of Contents
But how do you make this process go as smoothly as possible? How can you ensure that your website’s performance in search engine results is unaffected? How do you ensure that your users never get 404 errors?
Redirects are one of the easiest and most efficient ways to accomplish this. Redirects tell search engines and visitors which pages are no longer accessible and where they should go instead.
A wildcard redirect is one way to ensure that users end up exactly where you want them – regardless of how they type in your address or whether they leave out any details.
This article will explain how these work and why they are useful in practice.
What is a wildcard redirect?
A wildcard redirect is a type of redirect that allows you to redirect all traffic from one domain to another. This is useful if you want to move all of your traffic from one domain to another or if you want to redirect all traffic from a specific subdomain to another domain.
It is a redirecting option that allows browsers to reach your website regardless of the subdomain they requested (www.yourdomain.com or even anyname.yourdomain.com) without setting up specific directories for those requests in advance. It is also known as a “catch-all subdomain” or “wildcard subdomain.”
Catch-all subdomains also enable browsers to redirect requests for a mistyped, non-existent, or arbitrary subdomain to a valid webpage on your website.
How does a Wildcard Redirect work?
A wildcard redirect is a type of URL redirection that allows you to redirect all URLs that match a certain pattern to a single destination URL. This can be useful if you want to redirect multiple old URLs to a new URL or if you want to create vanity URLs for marketing purposes.
Landing page example:
For example, let’s say you have an eCommerce website and want to redirect all product pages from your old domain name (example.com) to your new domain name (example-store.com). You could do this with a wildcard redirect by setting up the following rule:
*.example.com -> https://www.example-store.
Website migration example
Wildcard redirects are often used when moving websites from one domain to another. For example, let’s say you have an old website at www.example.com and want to move it to www.newexample.com.
You could set up two separate redirects for each page on the old site (www. example.com/page1 to www.newexample.com/page1, www.example.com/page2 to www.newexample.com/page2, etc.), but that would be a lot of work.
Instead, you can set up a wildcard redirect from www.example.com/* to www.newexample.com/*, redirecting all traffic from the old site to the new site.
Benefits and uses of Wildcard Redirect
Web admins are well known for employing catch-all redirect to redirect massive volumes of files or pages to a new domain.
This can be useful in several scenarios:
- You’re changing domains and want to ensure that anyone who visits your old domain will be automatically redirected to your new one.
- You want to consolidate multiple domains into one main website. For example, if you have acquired another company and their domain now points to your website, you can set up a wildcard redirect so that all traffic from that domain is routed through yours.
- You want to set up a temporary redirect while making changes to your website. This allows you to redirect visitors to a temporary holding page, so they’re not seeing a broken website while you’re working on it.
- They are also used when restructuring a website when files must be transferred from one folder to another.
- You want to create a vanity URL. For example, you may want to set up a redirect from www.example.com/go to www.example.com/products so that visitors can more easily find your products page.
- You want to route traffic from a non-www version of your domain to the www version or vice versa.
- Changing the structure of your permalinks or slugs. If you do this, you should redirect URLs that use your old permalink or slug structure to your new one.
- Combining many posts into one. Some SEO gurus advise combining several little pieces into one massive one. If you do this, you should 301 redirect all minor posts to the main one.
What are some of the exceptions?
It’s important to note that a DNS record doesn’t cover the root domain. Therefore, the root domain lookups do not produce a catch-all result. Therefore, root records must be specified for root records that do not include sub-domain specifications.
Catch-alls do not replace existing records. Instead, it selects sub-domains at random and ignores those that have already been defined.
If you add a new subdomain, it will take priority over your wildcard.
Catch-all records only apply to the TXT, A, URL redirect, AAA, CNAME, and MX record types. They do not support NS records.
What about a 301 redirect?
You might think, “How about a 301 redirect?” at this point. Shouldn’t I use this instead? A 301 redirect, on the other hand, is best used when the website address has been permanently changed, such as to a new domain.
It will also be useful if several URLs can be used to visit the same webpage. In such circumstances, one domain is chosen, and the others are redirected. Finally, a 301 redirect is also a smart option if you want to integrate two sites.
A 301, on the other hand, does not take into account things like typos or strange domains. This implies that you may need to use both a 301 and a catch-all to transfer a domain name efficiently.
What about 302 redirects?
While 301 redirect refers to the permanent migration of a page to a different location, 302 redirect refers to temporary migration. Therefore, it does not transfer the link value to the new location. The advantage is that it does not redirect the visitor to the ‘404 not found’ error page but to a genuine website.
E-commerce sites can use it for out-of-stock products. For example, the 302 redirects may be used to send users to the product category page, where they can look for similar products.
How about .htaccess?
It normally takes some time for search engines to find a 301. This is why Google recommends testing your migration with a single subdomain or directory before moving the entire site.
Incorporating a 301 into the .htaccess file will “inform” search engines that a new link is in place of the old one. Here are several cases in which .htaccess could be useful:
- To “force” either a www or non-www domain version to be used
- To redirect individual files on the same domain
- To redirect files with a specific extension
- To redirect a new domain to a new one
How about meta refresh?
This redirect occurs at the page level and is slower. However, because of the diminished usability and loss of link equity, SEO professionals frequently ignore it. It is distinguished by a five-second flash of text that prompts you to click on a link if you are not redirected within five seconds.
Wildcard SSL certificates
As previously stated, wildcard redirects manage non-existent subdomains so that users can access a valid page regardless of the request. However, for wildcard redirection to work properly, they must be safe so that they do not jeopardize the integrity and security of your website. That is why wildcard SSL certificates are so important.
What is a wildcard SSL certificate?
This certificate ensures that the connection between the user’s internet browser and your website is safe. Furthermore, you can protect an unlimited number of principal subdomains with a single certificate. You’ll save money if you don’t have to get an SSL for every weird subdomain out there.
Here are some additional advantages of using wildcard SSL certificates.
Quick certificate processing
Your SSL certificates will be ready in two days. After domain confirmation, which takes a few minutes, you will have your certificate within two days.
Cost-effective
These certificates are regularly updated to meet the requests of new users. All updates are free of charge. So there’s no need to spend money to get the most recent updates. A trusted website seal, which you can get for free, can help assure your customers that your website is secure.
High compatibility
These certificates are often quite compatible across servers and devices. These SSL certificates are 99.9% compatible.
How to do a wildcard redirect?
Here are a few ways how you can use wildcard redirects.
Using .htaccess for wildcard redirect
This approach is useful when performing large-scale redirects. For example, if you want to redirect a whole domain to another. It allows you to add redirects by manually modifying the .htaccess file.
To access the .htaccess file, do the following steps:
- Access your cPanel.
- Then go to Files. Manager of files
- Select the website’s root folder.
- You may right-click in the folder and choose “Edit.”
If you do not currently have a .htaccess file, you have to create one. Here’s how to create it:
- On the top-left side, select “New File.”
- Give the file a name. Ensure the file is named .htaccess (don’t forget to include the dot at the beginning and write the filename in lowercase).
- Set the new .htaccess file’s directory to /public HTML/ or the document root of your website.
- Select ” edit ” if your text editor prompts you with an encoding dialog box.
- Here are several 301 redirects you can use to achieve various purposes after you access the .htaccess file (or after creating a new one).
Redirecting individual files
To redirect example.com/articles.htm to example.com/blog.htm. The 301 redirect to use is:
Redirect 301 /articles.htm /blog.htm
Redirecting an old domain to a new domain
Example:
From example.co to example.com. It is important to note that doing so will move your entire website. Insert the following code into the example.com .htaccess file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC,OR]
RewriteCond %{HTTP_HOST} www.example.com [NC]
RewriteRule ^(.*)$ http://example.co/$1 [L, R=301,NC]
Redirecting a specific file to another domain
Example:
example.com/articles.htm to example.com/blog.htm. The 301 redirect to use is:
Redirect 301 /articles.htm /blog.htm
Forcing the use of a www.version
Search engines distinguish example.com and www.example.com as two different websites.
You should choose one and use a 301 redirect to that one. The following code will be used to force the www version:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L, R=301,NC]
All files with a certain extension
Let’s assume you wish to redirect all files ending in.php from example.com/file.php to example.com/file.htm. Use the following code:
RewriteEngine on
RewriteCond %{REQUEST_URI} .php$
RewriteRule ^(.*).php$ /$1.htm [R=301,L]
Forcing the use of a non-www. version
Use the following code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L, R=301,NC]
Redirecting files to SSL
If you have added an SSL certificate to your website, you should include 301 redirects to transfer all HTTP traffic to HTTPS. Doing so ensures that your users have access to non-duplicate and safe content.
To redirect files to SSL, use the following code:
RewriteEngine on
RewriteCond %{HTTP} off
RewriteRule ^(.*)http://%{REQUEST_URI} [L,R=301]
How to do a wildcard redirect using .htaccess in WordPress?
To redirect your WordPress site, you must first enter the .htaccess file. This is how you do it:
- Go to the root folder of your WordPress site. You can do this using the File Manager in your cPanel or FTP.
- Once there, go to your .htaccess file.
- Before making any changes to your .htaccess file, make a backup.
- Then you can make the required changes (the code is the same as what we had looked at earlier when we discussed .htaccess in the previous section. Here we will cover what was not looked at then)
How to do a wildcard redirect in cPanel
When you wish to redirect traffic from one domain to another, using cPanel is a great option. This can be done at both the website example.com/about.html to (example.com/about-us/htm) and domain levels (example.com to example.co).
It is important to note that when you establish a redirect in cPanel, a redirect rule is immediately added to the .htaccess file.
Redirecting a full domain to a new one
What you must do is as follows:
- Log in to your cPanel
- Navigate to the “Domains” section
- Select the redirect option. This will take you to the Add Redirect page.
- Select “Type” from the dropdown menu
- Choose between a permanent and temporary redirect
- Select the next option from the dropdown menu
- Select the domain to which you wish to redirect
- You can enter important folder names under the slash (/) area
- Navigate to the “redirects to” box and enter the address you wish to redirect to
- Select the desired redirect option (“only redirect with www,” “do not redirect with www,” or “redirect with or without www”)
- Check the box to create a wildcard redirect
- After the redirected URL, the wildcard contains the file/folder name. Thus example.com/tests.php redirects to example.com/tests.php
- When you’re finished, tap add
- The specifics of your reroute will be displayed
How to do a wildcard redirect with Simple 301 Redirects WordPress Plugin
Wildcards are incredibly simple to utilize in Simple 301 Redirects. First, install and activate the plugin to get started. Once activated, navigate to Settings 301 Redirects to begin configuring some 301 redirects:
To create new redirect links for all files in one directory, go to Settings-> 301 Redirects in your WordPress dashboard and tick the ‘Use Wildcards’ checkbox.
Use an asterisk ‘‘ after the old dynamic URL includes the old category and another asterisk ” after the new destination dynamic URL. Then, under the Simple 301 Redirects plugin, click the ‘Add New’ button to generate new redirect URLs with Wildcards.
Example:
Request: /old-folder/*
Destination: /wildcard-redirect-everything-to-here/
You can also use the asterisk in the destination to replace whatever it matched in the request if you like. Something like this:
Example:
Request: /old-folder/*
Destination: /one/two/new-folder/*
Or:
Request: /old-folder/*/content/
Destination: /one/two/new-folder/*
That’s how you can easily use Wildcards to generate redirect URLs in Simple 301 Redirects.
A few things to consider
You can achieve a lot of redirection needs with those code snippets, but to keep things neat (and prevent going in circles), consider following these rules when setting up redirects:
- When possible, avoid “stacking” redirects. This confuses and is not advised for SEO.
- Before testing, ensure that your hosting and local caches are completely clear. Using a Chrome Incognito window at this time is a good option because your browser will frequently cache redirects behind the scenes, preventing you from seeing changes to existing redirects immediately. Also, check if you use a caching plugin, host-based cache, or Cloudflare cache.
- If the Redirection plugin causes too many redirect loops, talk to your server about redirecting with .htaccess. The regular expression formatting is almost the same, but by using .htaccess, you can ensure that the annoying redirects are done before the WordPress ones, which generally resolves any outstanding issues.
Conclusion
Moving a website or domain is not a simple task. It is a task that must be completed with caution and strategy to prevent losing visitors and negatively impacting your Google rating. Using wildcard redirects makes this a piece of cake.
They are also useful for rebranding, changing domains, or doing anything else that may cause a redirect. Wildcard SSL certificates will keep your website safe, particularly if you use a wildcard subdomain redirect.