What is Wildcard redirect?

Contents

Wildcard redirect: What it is and why use it

There are moments when moving your site is inevitable. This could be due to a rebranding, redesign, or traffic redirection towards updated content. 

But how do you make this process a breeze? How do you make sure the performance of your website on search engine results is not affected? How do you make sure your users never get the 404 errors?

Here we tell you how to move your site effortlessly, with more emphasis on how you can achieve that using wildcard.

What is a wildcard redirect?

Also commonly known as a "catch-all subdomain" or "wildcard subdomain", it is a redirecting option that allows browsers to reach your website no matter what subdomain they requested (www.yourdomain.tld or even anyname.yourdomain.tld) without having to set up specific directories for those requests in advance. 

Catch-all subdomains also allow browsers to redirect their request for a mistyped, non-existent, or random subdomain to a valid page on your site. 

What are some of the exceptions?

It is good to note that a DNS record does not cover a root domain. The root domain lookups don’t return a catch-all. Root records must be defined for root records without sub-domain specifications. 

Catch-alls do not supersede already existing records. Instead, it chooses the random sub-domains and dismisses the already defines ones. 

More exceptions

If you create a different subdomain, it will take precedence over your wildcard.

Catch-all records only work for A, TXT, URL redirect, CNAME, AAA, and MX record types. They do not work with NS records.

Uses of wildcard redirect

Webmasters are best known for using catch-alls redirect to redirect files or pages in large volumes to a new domain. 

They are also utilized when restructuring a website when the files need to be moved from an existing folder to a new one.

Additionally, they come in handy in fixing broken backlinks so that users can enjoy an error-free browsing experience.

Wildcard SSL certificates

As mentioned above, wildcard redirects handle subdomains that are non-existent so that users can access a valid page irrespective of the request. For the wildcard redirects to function this way, they need to be secure in order not to compromise the integrity and security of your website. That is why wildcard SSL certificates are very crucial.

What is a wildcard SSL certificate?

The purpose of this certificate is to ensure that the connection between the user’s browsing the internet and your website is secure. Additionally, with a single certificate, you shield unlimited and primary subdomains. That way you save money compared to when you have to buy an SSL for every random sub-domain out there.

Here are more benefits of using wildcard SSL certificates.

Quick certificate processing

Within two days, your SSL certificates will be ready. Once domain validation is complete, which takes a few minutes, within two days, you will have your certificate.

Cost-effective

These certificates are constantly updated to cater to new user requests. All updates are done at no extra cost. So, no dropping some dollars to get the latest updates. Trusted website seal, which you can get at no extra cost, help you assure your users that your website is secure. 

How to do a wildcard redirect?

Here are a few different ways that you can use wildcard redirects.

Using .htaccess for wildcard redirect

This method comes in handy when looking to do major redirects. For example, when planning to redirect a whole domain to another. It allows you to add redirects by directly modifying the .htaccess file manually. 

To access the .htaccess file, do the following:

  • Log in to your cPanel 
  • Go to Files then File manager

cpanel file manager

  • Choose website root folder
  • In the folder you can right-click and select "Edit"
  • htaccess file

    If you do not have .htaccess file, already, you need to create one. Here is how to create it:

    • Tap “New File” on the top-left side 
    • Name the file. Make sure the file is named .htaccess (don’t forget to add the dot at the beginning and to write the filename in lower case)
    • Set the directory of the new .htaccess file to /public_html/ or your website’s document root 
    • If your text editor displays an encoding dialog box, hit “edit.”
    • Once you have access to .htaccess file (or after creating a new one), here are some 301 redirects that you can implement to realize different goals.

    Redirecting individual files 

    To redirect seo.com/news.htm to seo.com/media.htm. below is the 301 redirect to use:

    Redirect 301 /news.htm /media.htm

    Redirecting an old domain to a new domain

    Example:

    From seo.co to seo.com. It is good to note that doing this will move your entire website. Include the following code in the seo.com .htaccess:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^seo.com [NC,OR]
    RewriteCond %{HTTP_HOST} www.seo.com [NC]
    RewriteRule ^(.*)$ http://seo.co/$1 [L, R=301,NC]

    Redirecting a specific file to another domain

    Example: 

    seo.com/news.htm to seo.com/media.htm. Below is the 301 redirect to use:

    Redirect 301 /news.htm http://seo.ke/media.htm 

    Forcing the use of a www. version

    Search engines see seo.com and www.seo.com as two different sites.It is recommended to choose one and use a 301 redirect to the one you pick. Here is the code you will use to force the www version:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^seo.com [NC]
    RewriteRule ^(.*)$ http://www.seo.com/$1 [L, R=301,NC]

    Redirecting all files with a certain extension 

    Let’s assume you want to redirect all files with a .php extension, from seo.com/file.php to seo.com/file.htm. Use this code: 

    RewriteEngine on
    RewriteCond %{REQUEST_URI} .php$
    RewriteRule ^(.*).php$ /$1.htm [R=301,L]

    Forcing the use of a non-www. version 

    Use this code: 

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.seo.com [NC]
    RewriteRule ^(.*)$ http://seo.com/$1 [L, R=301,NC]

    Making a smooth transition

    With those code snippets, you can accomplish a lot of redirection needs but to make everything clean (and avoid running around in a lot of circles), consider following these guidelines when setting up redirects:

    • Avoid “stacking” redirects when possible. Doing that confuses and is not recommended for SEO.
    • Before testing, make sure your hosting caches and local caches are fully clear. Using a Chrome Incognito window is a good idea at this time because your browser will often cache redirects behind the scenes, hence preventing you from seeing changes to existing redirects instantly. If you are using a caching plugin, host-based cache, or Cloudflare cache, make sure that is clear too.
    • If you are getting too many redirect loops with the Redirection plugin, contact your host about redirecting with .htaccess. The regular expression formatting is similar, but using .htaccess can ensure the annoying redirects are executed before the WordPress ones, which usually resolve any pending issues.

    Redirecting files to SSL

    In case you have added an SSL certificate to your website, it is a good idea to include 301 redirects that will send all HTTP traffic to HTTPS. By doing this, you make sure your users access non-duplicate and secure content.

    Use this code to redirect files to SSL:

    RewriteEngine on
    RewriteCond %{HTTP} off
    RewriteRule ^(.*)http://%{REQUEST_URI} [L,R=301]

    Redirecting an entire domain to a new one

    In case you decide to move the entire WordPress website to a completely new domain, for example, from seo.com to seo.co, then add the following code to the domain name’s .htaccess file (seo.com)

    #Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^(.*)$ http://www.seo.co$1 [,R=301,L]

    How to use cPanel to perform wildcard redirect

    Using cPanel is a great idea when you want to redirect traffic from one domain to another. This can be done at both the webpage level (seo.com/about.html to seo.com/about-us/htm) and domain level (seo.com to seo.co).

    Note that when you create a redirect in cPanel, a redirect rule is automatically included in the .htaccess file.

    Redirecting a full domain to a new one 

    Here is what you need to do: 

    • Login to cPanel 
    • Go to the “Domains” section 
    • Tap the redirect button. This will open the Add Redirect page

    cpanel redirect section

    • Tap the “Type” dropdown 
    • Select a permanent or temporary redirect 
    • Tap the next dropdown menu 
    • Choose the domain you want to redirect 


    • You can add essential folder names under the slash (/) field 
    • Go to the “redirects to” section and key in the address to which you want to redirect to 
    • Choose the desired redirect option (“only redirect with www”, “do not redirect www.”, and “redirect with or without www” 
    • To create a wildcard redirect, check the box
    • The wildcard includes the file/folder name after the redirected URL, for instance, abc.com/tests.php redirects to ab.com/tests.php 
    • Tap add when you are done. 
    • The details of your redirect will pop up

    Wrapping up

    Moving a website or domain is not a breeze. It is a task that needs to be done cautiously and strategically, to avoid losing traffic and affecting your ranking on Google. Using wildcard redirects makes this a breeze. They also come in handy when rebranding, not changing domains, or anything that may require a redirect. Most notably, wildcard SSL certificates will keep your website secure, especially after doing a wildcard subdomain redirect.