There are times when you have to move your website or parts of it. This could be due to a new domain name, a new website platform, or a major content update. When you do this, you want to make sure your website’s performance isn’t affected and that your users don’t get a 404 error.
This is where a wildcard redirect comes in. It’s a redirecting option that allows you to move an entire section of your website at once, saving you a lot of time and effort.
More information about redirects in general
(This heading from the original content does not have a body of text, so I will skip it. The information has been incorporated into the other sections.)
What is a wildcard redirect?
A wildcard redirect is a redirecting option that allows you to send all of the URLs in a folder or on a domain to a new location. It is also known as a “catch-all subdomain” because it can send a user to a valid page on your site even if they type in a mistyped or non-existent URL.
How to do a wildcard redirect?
Using .htaccess for wildcard redirect
The .htaccess file is a configuration file for Apache servers. This file can be used for many things, including setting up wildcard redirects. You can edit the file from your website’s control panel or by using an FTP client.
Redirecting individual files
To redirect a single file, you can use a 301 redirect like this:
Redirect 301 /news.htm /media.htm
Redirecting entire folders
If you want to redirect all the URLs in a folder, you can use this code:
RewriteEngine on RewriteRule ^old-folder/(.*)$ /new-folder/$1 [L,NC,R=301]
This will redirect /old-folder/article to /new-folder/article, and all other files in that folder.
Redirecting an old domain to a new domain
If you want to redirect all traffic from an old domain to a new one, you can use this code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^old-seo.com [NC,OR] RewriteRule ^(.*)$ http://seo.com/$1 [L,R=301,NC]
Forcing the use of a www. version
Search engines see seo.com and www.seo.com as two different sites. You should choose one and use a 301 redirect to send all traffic to the one you choose. Here is the code you will use to force the www version:
RewriteEngine on RewriteCond %{HTTP_HOST} ^seo.com [NC] RewriteRule ^(.*)$ https://www.seo.com/$1 [L,R=301,NC]
Forcing the use of a non-www. version
If you want to use the non-www version of a site, use this code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^www.seo.com [NC] RewriteRule ^(.*)$ https://seo.com/$1 [L,R=301,NC]
Redirecting all files with a certain extension
If you want to redirect all files with a .php extension to a .htm extension, you can use this code:
RewriteEngine on RewriteCond %{REQUEST_URI} .php$ RewriteRule ^(.*).php$ /$1.htm [R=301,L]
Redirecting files to SSL
If 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. Use this code to redirect files to SSL:
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Redirects and status codes
As you have seen in the code snippets above, you can specify the redirect status code (301 for permanent, 302 for temporary). If the move is permanent, you should always use a 301 status code. This helps search engines understand that this is the new URL and that they should use it from now on.
How to use cPanel to perform wildcard redirect
If you are using a hosting control panel, you can use it to perform wildcard redirects. This can be done at both the webpage level and the domain level. When you create a redirect in a control panel, a redirect rule is automatically included in the .htaccess file.
Redirecting a full domain to a new one
To redirect a full domain to a new one, you can log in to your control panel, go to the Domains section, and select the redirect option. From there, you can choose the domain you want to redirect and the new domain you want to redirect to. You can also create a wildcard redirect, which will redirect all the files in a folder to the new domain.
How to use cPanel to change your .htaccess file
If you are using a hosting control panel, you can use the File Manager to change your .htaccess file. You can find the file in your website’s root folder. If you do not have a .htaccess file, you can create a new one.
Making a smooth transition
When you are setting up redirects, you should avoid “stacking” them. This is when a user is redirected from page A to page B to page C. This is slower and is not recommended for SEO. It is always better to redirect to the correct URL directly.
Wrapping up
Moving a website or domain can be tricky, but when done correctly, it can save your SEO. Using a wildcard redirect can make this a breeze. An automated SEO platform like Clickrank can help you with your redirects and other SEO tasks, so you can focus on building a great website.
What is a wildcard redirect?
A wildcard redirect is a redirecting option that allows you to send all of the URLs in a folder or on a domain to a new location.
How do I perform a wildcard redirect?
You can perform a wildcard redirect by using a hosting control panel or by editing your .htaccess file.
What is the difference between a 301 and a 302 redirect?
A 301 redirect is a permanent redirect that tells search engines a page has moved for good. A 302 redirect is a temporary redirect that tells a search engine a page has moved for a short time.
What is a redirect chain?
A redirect chain is when a user is redirected from page A to page B to page C. It is a bad practice that can slow down your website and waste a search engine's crawl budget.