Redirects for SEO must be used properly since they impact how websites are crawled and indexed by Google.
While many people consider redirects as a web detour sign, much more is occurring, and it’s remarkably pleasurable to find.
Keep reading for an extensive summary of redirects and the proper application for technical SEO.
What Is A Redirect?
Website reroutes inform internet browsers and search engines information about a URL and where to find the webpage.
A URL redirect includes code carried out to a specific URL, or a group of URLs so that the user (or online search engine) is sent out to a various page to the actual URL that was input or clicked.
A redirect can be set as a:
- Short-term redirect: 302, 303, 307, 308.
- Irreversible redirect: 301.
When To Use Redirects
The primary reasons to utilize redirects are:
- A private page or entire domain has been moved (URL altered).
- To allow the use of URL shorteners or ‘quite URLs.’
- Website migration (e.g., HTTP to HTTPS).
For SEO purposes, URL redirects are important since they:
- Forward authority of any links pointing to a page that has actually moved or been deleted.
- Avoid 404 page not discovered mistakes (although in some cases it is much better to leave a 404).
Redirects can be implemented on a group or domain-wide basis however typically need to be set on a specific basis to prevent issues.
When utilizing RegEX for group reroutes, it can have unforeseen results if your reasoning isn’t perfect!
Kinds of Redirects
There are three primary types of redirects:
- Meta Refresh redirects are set at the page level but are usually not recommended for SEO functions. There are two types of meta redirect: postponed which is viewed as a short-term redirect, and instant, which is viewed as an irreversible redirect.
- HTTP redirects are set server-side and the best method for SEO purposes– we covered in-depth listed below.
What Is A HTTP Action Status Code?
Web browsers and search engine spiders like GoogleBot are called user representatives.
When a user agent tries to access a webpage, what happens is that the user representative makes a demand, and the site server problems a reaction.
The reaction is called an HTTP response status code. It offers a status for the request for a URL.
In the situation where a user agent like GoogleBot requests a URL, the server provides an action.
For example, if the request for a URL succeeds, the server will supply an action code of 200, which indicates the request for a URL succeeded.
So, when you think of a GoogleBot reaching a site and attempting to crawl it, what’s occurring is a series of requests and actions.
An HTTP redirect is a server response to ask for a URL.
If the URL exists at a different URL (due to the fact that it was moved), the server tells the user representative that the URL demand is being rerouted to a different URL.
The action code for a changed URL is normally in the kind of a 301 or 302 reaction status code.
The whole 3xx series of response codes communicate much details that can optionally be acted on by the user representative.
An example of an action that the user agent can take is to conserve a cache of the brand-new URL so that the next time the old URL is asked for, it will request the new URL instead.
So, a 301 and a 302 redirect is more than a web road indication that says, “Go here, not there.”
3XX Series Of Status Codes
Redirects are more than simply the 2 status codes everyone is familiar with, the 301 and 302 action codes.
There are a total of 7 main 3xx reaction status codes.
These are the different kinds of redirects offered for usage:
- 300 Multiple Options.
- 301 Moved Permanently.
- 302 Found.
- 303 See Other.
- 304 Not Customized.
- 305 Usage Proxy.
- 306 (Unused).
- 307 Temporary Redirect.
- 308 Permanent Redirect.
A few of the above status codes have not been around as long and might not be utilized. So, before using any redirect code aside from 301 or 302, make certain that the desired user agent can translate it.
Because GoogleBot utilizes the most recent version of Chrome (called a headless browser), it’s easy to check if a status code works by checking if Chrome recognizes the status code with a web browser compatibility list.
For SEO, one need to stick to using the 301 and 302 response codes unless there is a specific factor to utilize one of the other codes.
301: Moved Completely
The 301 status code is routinely referenced as the 301 redirects. However the main name is 301 Moved Completely.
The 301 redirect indicates to a user agent that the URL (sometimes described as a target resource or just resource) was altered to another location which it ought to use the brand-new URL for future demands.
As mentioned earlier, there is more info too.
The 301 status code likewise suggests to the user agent:
- Future requests for the URL ought to be made with the brand-new URL.
- Whoever is making the demand ought to update their links to the new URL.
- Subsequent requests can be altered from GET to POST.
That last point is a technical problem. According to the official requirements for the 301 status code:
“Keep in mind: For historic reasons, a user representative MAY change the demand technique from POST to GET for the subsequent request. If this behavior is undesired, the 308 (Permanent Redirect) status code can be used instead.”
For SEO, when search engines see a 301 redirect, they pass the old page’s ranking to the new one.
Prior to making a change, you should take care when using a 301 redirect. The 301 redirects need to only be utilized when the change to a brand-new URL is irreversible.
The 301 status code must not be used when the modification is temporary.
Furthermore, if you change your mind later and return to the old URL, the old URL might not rank anymore and might take time to regain the rankings.
So, the main thing to remember is that a 301 status code will be utilized when the change is irreversible.
The main thing to comprehend about the 302 status code is that it works for circumstances where a URL is momentarily changed.
The meaning of this response code is that the URL is momentarily at a various URL, and it is suggested to utilize the old URL for future requests.
The 302 redirect status code likewise features a technical caveat related to GET and Post:
“Keep in mind: For historic reasons, a user representative MAY alter the request method from POST to GET for the subsequent request. If this behavior is unwanted, the 307 (Short-term Redirect) status code can be utilized instead.”
The referral to “historic reasons” might refer to old or buggy user agents that might alter the request method.
307: Temporary Redirect
A 307 redirect implies the asked for URL is briefly moved, and the user agent need to utilize the initial URL for future demands.
The only distinction between a 302 and a 307 status code is that a user representative need to request the brand-new URL with the same HTTP request used to ask for the original URL.
That suggests if the user agent requests the page with a GET demand, then the user representative must use a GET ask for the brand-new momentary URL and can not utilize the POST request.
The Mozilla documentation of the 307 status code explains it more plainly than the official documents.
“The server sends this reaction to direct the customer to get the asked for resource at another URI with very same method that was used in the prior request.
This has the very same semantics as the 302 Found HTTP reaction code, with the exception that the user representative should not change the HTTP method used: if a POST was used in the very first request, a POST must be utilized in the 2nd demand.”
Besides the 307 status code needing subsequent requests to be of the very same kind (POST or GET) which the 302 can go in any case, whatever else is the same between the 302 and the 307 status codes.
302 Vs. 307
You might deal with a redirect by means of server config files.htaccess on Apache, example.conf file on Nginx or by means of plugins if you are using WordPress.
In all instances, they have the very same syntax for composing redirect rules. They vary just with commands utilized in configuration files. For instance, a redirect on Apache will appear like this:
Alternatives +FollowSymlinks RewriteEngine on RedirectMatch 301 ^/ oldfolder// newfolder/
(You can check out symlinks here.)
On Nginx servers, it will look like this:
rewrite ^/ oldfolder// newfolder/ irreversible;
The commands utilized to tell the server’s status code of redirect and the action command vary.
- Servers status code of redirect: “301 ″ vs. “permanent.”
- Action command: “RedirectMatch” vs. “reword.”
However the redirect syntax (^/ oldfolder// newfolder/) is the exact same for both.
On Apache, guarantee that mod_rewrite and mod_alias modules (accountable for managing redirects) are allowed on your server.
Given that the most extensively spread out server type is Apache, here are examples for.htaccess apache files.
Ensure that the.htaccess file has these 2 lines above the redirect rules and put the rules listed below them:
Options +FollowSymlinks RewriteEngine on
Read the main documentation to find out more about the RewriteEngine.
To understand the examples listed below, you may refer to the table below on RegExp basics.
|*||no or more times|
|.||any single character|
|?||No or one time|
|^||Start of the string|
|$||End of the string|
|| b||OR operadn” |” a or b|
|(z)||remembers the match to be utilized when calling $1|
How To Produce Redirects
How To Create A Redirect For A Single URL
The most typical and extensively used kind of redirect is when erasing pages or altering URLs.
For instance, say you altered the URL from/ old-page/ to/ new-page/. The redirect guideline would be:
RewriteRule ^ old-page(/? |/. *)$/ new-page/ [R=301, L] Or RedirectMatch 301 ^/ old-page(/? |/. *)$/ new-page/
The only distinction in between the 2 approaches is that the first uses the Apache mod_rewrite module, and the second usages mod_alias. It can be done using both approaches.
The regular expression “^” suggests the URL must start with “/ old-page” while (/? |/. *)$ shows that anything that follows “/ old-page/” with a slash “/” or without a precise match needs to be redirected to/ new-page/.
We could likewise utilize (. *), i.e., ^/ old-page(. *), but the issue is, if you have another page with a similar URL like/ old-page-other/, it will likewise be redirected when we only wish to reroute/ old-page/.
The following URLs will match and be directed to a brand-new page:
|/ old-page/||/ new-page/|
|/ old-page||/ new-page/|
|/ old-page/? utm_source=facebook.com||/ new-page/? utm_source=facebook.com|
|/ old-page/child-page/||/ new-page/|
It will reroute any variation of the page URL to a new one. If we utilize redirect in the following form:
Redirect 301/ old-page// new-page/
Without regular expressions, all URLs with UTM question string, e.g.,/ old-page? utm_source=facebook.com (which prevails since URLs are utilized to be shared over a social network), would wind up as 404s.
Even/ old-page without a trailing slash “/” would wind up as a 404.
Redirect All Except
Let’s state we have a bunch of URLs like/ category/old-subcategory -1/,/ category/old-subcategory -2/,/ category/final-subcategory/ and wish to combine all subcategories into/ category/final-subcategory/. We need the “all other than” rule here.
Otherwise, if we have some possessions like “/ category/image. jpg,” it will likewise be rerouted to “/ final-subcategory/” and cause an image break.
Directory site Modification
You can utilize the guideline below if you did a classification restructuring and want to move whatever from the old directory site to the brand-new one.
RewriteRule ^ old-directory$/ new-directory/ [R=301, NC, L] RewriteRule ^ old-directory/(. *)$/ new-directory/$1 [R=301, NC, L] I utilized $1 in the target to inform the server that it ought to keep in mind whatever in the URL that follows/ old-directory/ (i.e.,/ old-directory/subdirectory/) and pass it (i.e., “/ subdirectory/”) onto the location. As an outcome, it will be redirected to/ new-directory/subdirectory/.
I utilized two guidelines: one case without any tracking slash at the end and the other one with a trailing slash.
I could combine them into one rule utilizing (/? |. *)$ RegExp at the end, but it would cause issues and add a “//” slash to the end of the URL when the requested URL without any trailing slash has a question string (i.e., “/ old-directory? utm_source=facebook” would be rerouted to “/ new-directory//? utm_source=facebook”).
Eliminate A Word From URL
Let’s say you have 100 URLs on your site with the city name “Chicago” and want to eliminate them.
For the URL http://yourwebiste.com/example-chicago-event/, the redirect guideline would be:
RewriteRule ^(. *)-chicago-(. *) http://% /$1-$2 [NC, R=301, L] If the example URL is in the form http://yourwebiste.com/example/chicago/event/, then the redirect would be: RewriteRule ^(. *)/ chicago/(. *) http://% SERVER_NAME/$1/$2 [NC, R=301, L] Set A Canonical URL
Having canonical URLs is the most fundamental part of SEO.
If missing, you might threaten your website with duplicate content concerns due to the fact that online search engine deal with URLs with “www” and “non-www” variations as different pages with the very same material.
Therefore, you should guarantee you run the site just with one variation you pick.
If you want to run your site with the “www” variation, use this rule:
RewriteCond % HTTP_HOST ^ yourwebsite.com [NC] RewriteRule ^(. *)$ http://www.yourwebsite.com/$1 [L, R=301] For a “non-www” variation: RewriteCond % HTTP_HOST ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ http://yourwebsite.com/$1 [L, R=301] Tracking slash is also part of canonicalization because URLs with a slash at the end or without are likewise treated differently. RewriteCond % REQUEST_FILENAME!-f RewriteRule ^(. * [^/]$/$1/ [L, R=301] This will ensure the/ example-page is redirected to/ example-page/. You might pick to remove the slash rather of adding then you will need the other rule below: RewriteCond % REQUEST_FILENAME!-d RewriteRule ^(. *)/$/$1 [L, R=301]HTTP To HTTPS Redirect
After Google’s initiative to encourage website owners to use SSL, migrating to HTTPS is one of the frequently used redirects that almost every website has.
The rewrite rule below can be used to require HTTPS on every website.
RewriteCond % HTTP_HOST ^ yourwebsite.com [NC, OR] RewriteCond % ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ https://www.yourwebsite.com/$1 [L, R=301, NC] Using this, you can integrate a www or non-www variation reroute into one HTTPS redirect rule.
Redirect From Old Domain To New
This is also among the most used redirects when you choose to rebrand and require to alter your domain. The guideline listed below reroutes old-domain. com to new-domain. com.
RewriteCond % ^ old-domain. com$ [OR] RewriteCond % ^ www.old-domain.com$ RewriteRule (. *)$ http://www.new-domain.com/$1 [R=301, L] It utilizes two cases: one with the “www” variation of URLs and another “non-www” since any page for historic reasons might have incoming links to both versions.
A lot of site owners utilize WordPress and might not require a.htaccess file for redirects however utilize a plugin instead.
Handling redirects utilizing plugins might be a little various from what we talked about above. You might require to read their paperwork to manage RegExp correctly for the specific plugin.
From the existing ones, I would suggest a free plugin called Redirection, which has lots of parameters to manage redirect guidelines and numerous helpful docs.
Redirect Finest Practices
1. Do not Reroute All 404 Broken URLs To The Homepage
This case typically occurs when you are too lazy to investigate your 404 URLs and map them to the suitable landing page.
According to Google, they are still all dealt with as 404s.
Yeah, it’s not a great practice (confuses users), and we mainly treat them as 404s anyhow (they’re soft-404s), so there’s no advantage. It’s not seriously broken/bad, but extra intricacy for no great reason– make a much better 404 page instead.
— John (@JohnMu) January 8, 2019
If you have too many pages like this, you ought to think about developing lovely 404 pages and engaging users to search more or discover something besides what they were searching for by displaying a search choice.
It is strongly recommended by Google that redirected page content need to be comparable to the old page. Otherwise, such a redirect might be considered a soft 404, and you will lose the rank of that page.
2. Get Mobile Page-Specific Redirects Right
If you have various URLs for desktop and mobile websites (i.e., “example.com” for desktop and “m.example.com” for mobile), you need to ensure to redirect users to the proper page of the mobile version.
Correct: “example.com/sport/” to “m.example.com/sport/”
Wrong: “example.com/sport/” to “m.example.com”
Likewise, you have to guarantee that if one page is 404 on the desktop, it must likewise be 404 on mobile.
If you have no mobile variation for a page, you can prevent rerouting to the mobile variation and keep them on the desktop page.
3. How To Utilize Meta Refresh
It is possible to do a redirect utilizing a meta refresh tag like the example below:
If you insert this tag in/ old-page/, it will redirect the user right away to/ new-page/.
Google does not restrict this redirect, however it doesn’t recommend using it.
A meta revitalize type redirect ought to just work. We don’t advise it for 2 factors: UX (it keeps the page in web browser history, afaik) & processing time (we require to parse the page to see it). As soon as processed, it’s similar to a redirect.
— John (@JohnMu) March 2, 2018
4. Avoid Redirect Chains
This message shows when you have a wrong regular expression setup and winds up in an infinite loop.
Screenshot by author, December 2022 Typically, this occurs when you have a redirect chain. Let’s say you redirected page 1 to page 2 a long time ago. You may have forgotten that
page 1 is redirected and chosen to reroute page 2 to page 1 once again. As an outcome, you will end up with a rule like this: RewriteRule ^ page1/ page2 [R
=301, NC, L] RewriteRule ^ page2/ page1 [R=301, NC, L] This will develop a boundless loop and produce the error revealed above. Conclusion Knowing what
redirects are and which situation requires a specific status code is basic to
webpages effectively. It’s a core part of understanding SEO. Lots of scenarios require accurate understanding of redirects, such as moving a site to a new domain or developing a temporary holding page URL for a web page that will return under its typical URL. While so much is possible with a plugin, plugins can be misused without effectively comprehending when and why to utilize a specific
kind of redirect. More Resources: Featured Image: