Redirects for SEO must be used correctly since they affect how sites are crawled and indexed by Google.
While many people think about redirects as an internet detour sign, much more is taking place, and it’s remarkably satisfying to find.
Keep checking out for a comprehensive overview of redirects and the correct application for technical SEO.
What Is A Redirect?
Site redirects inform internet browsers and online search engine information about a URL and where to find the webpage.
A URL redirect includes code carried out to a particular URL, or a group of URLs so that the user (or search engine) is sent out to a different page to the real URL that was input or clicked.
A redirect can be set as a:
- Short-lived redirect: 302, 303, 307, 308.
- Long-term redirect: 301.
When To Use Redirects
The main reasons to utilize redirects are:
- A specific page or entire domain has actually been moved (URL altered).
- To enable the usage of URL shorteners or ‘pretty URLs.’
- Site migration (e.g., HTTP to HTTPS).
For SEO functions, URL redirects are essential due to the fact that they:
- Forward authority of any links pointing to a page that has moved or been deleted.
- Avoid 404 page not found errors (although in some cases it is better to leave a 404).
Redirects can be executed on a group or domain-wide basis however often need to be set on an individual basis to prevent concerns.
When using RegEX for group redirects, it can have unforeseen outcomes if your logic isn’t flawless!
Kinds of Redirects
There are three main types of redirects:
- Meta Refresh redirects are set at the page level but are usually not recommended for SEO purposes. There are 2 types of meta redirect: delayed which is seen as a short-lived redirect, and instant, which is viewed as a long-term redirect.
- HTTP redirects are set server-side and the very best technique for SEO functions– we covered extensive below.
What Is A HTTP Response Status Code?
Web browsers and search engine spiders like GoogleBot are called user representatives.
When a user representative attempts to access a website, what occurs is that the user representative makes a demand, and the site server problems an action.
The reaction is called an HTTP reaction status code. It supplies a status for the ask for a URL.
In the situation where a user representative like GoogleBot demands a URL, the server gives a response.
For example, if the request for a URL is successful, the server will provide an action code of 200, which indicates the request for a URL achieved success.
So, when you consider a GoogleBot reaching a website and trying to crawl it, what’s happening is a series of requests and reactions.
An HTTP redirect is a server response to request a URL.
If the URL exists at a various URL (since it was moved), the server informs the user agent that the URL demand is being rerouted to a various URL.
The action code for a changed URL is typically in the type of a 301 or 302 action status code.
The whole 3xx series of response codes interact much details that can additionally be acted on by the user agent.
An example of an action that the user representative can take is to save a cache of the brand-new URL so that the next time the old URL is requested, it will request for the brand-new URL instead.
So, a 301 and a 302 redirect is more than an internet roadway indication that states, “Go here, not there.”
3XX Series Of Status Codes
Redirects are more than simply the 2 status codes everybody is familiar with, the 301 and 302 response codes.
There are an overall of 7 main 3xx response status codes.
These are the different kinds of redirects offered for usage:
- 300 Multiple Options.
- 301 Moved Completely.
- 302 Found.
- 303 See Other.
- 304 Not Customized.
- 305 Use Proxy.
- 306 (Unused).
- 307 Temporary Redirect.
- 308 Long-term Redirect.
Some of the above status codes have actually 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 intended user representative can analyze it.
Due to the fact that GoogleBot utilizes the latest variation of Chrome (called a headless browser), it’s easy to inspect if a status code works by checking if Chrome recognizes the status code with a browser compatibility list.
For SEO, one must adhere to utilizing the 301 and 302 reaction codes unless there is a particular factor to use among the other codes.
301: Moved Permanently
The 301 status code is routinely referenced as the 301 redirects. However the official name is 301 Moved Permanently.
The 301 redirect shows to a user agent that the URL (sometimes referred to as a target resource or merely resource) was changed to another location which it must utilize the brand-new URL for future demands.
As discussed earlier, there is more info also.
The 301 status code also recommends to the user agent:
- Future requests for the URL must be made with the new URL.
- Whoever is making the demand must upgrade their links to the new URL.
- Subsequent demands can be changed from GET to POST.
That last point is a technical issue. According to the main standards for the 301 status code:
“Note: For historic reasons, a user agent MAY alter the request technique from POST to GET for the subsequent demand. If this habits is undesired, the 308 (Irreversible Redirect) status code can be used rather.”
For SEO, when online search engine see a 301 redirect, they pass the old page’s ranking to the brand-new one.
Before making a modification, you should beware when using a 301 redirect. The 301 redirects should only be utilized when the modification to a new URL is long-term.
The 301 status code need to not be used when the change is temporary.
In addition, if you change your mind later on and return to the old URL, the old URL may not rank anymore and may require time to gain back the rankings.
So, the main thing to keep in mind is that a 301 status code will be used when the modification is permanent.
The main thing to understand about the 302 status code is that it’s useful for situations where a URL is temporarily changed.
The meaning of this reaction code is that the URL is briefly at a different URL, and it is suggested to utilize the old URL for future demands.
The 302 redirect status code also features a technical caveat associated to GET and Post:
“Keep in mind: For historic reasons, a user agent MAY change the request approach from POST to GET for the subsequent demand. If this habits is unwanted, the 307 (Short-lived Redirect) status code can be used rather.”
The recommendation to “historical factors” might describe old or buggy user representatives that may alter the demand technique.
307: Temporary Redirect
A 307 redirect implies the requested URL is momentarily moved, and the user agent must utilize the initial URL for future requests.
The only difference in between a 302 and a 307 status code is that a user agent must ask for the brand-new URL with the exact same HTTP demand utilized to ask for the initial URL.
That implies if the user representative demands the page with a GET demand, then the user agent need to use a GET request for the new temporary URL and can not utilize the POST demand.
The Mozilla documents of the 307 status code explains it more plainly than the official paperwork.
“The server sends this response to direct the customer to get the asked for resource at another URI with very same technique that was used in the previous demand.
This has the very same semantics as the 302 Found HTTP response code, with the exception that the user agent should not change the HTTP technique used: if a POST was used in the first demand, a POST needs to be utilized in the 2nd demand.”
Other than the 307 status code requiring subsequent demands to be of the exact same kind (POST or GET) and that the 302 can go either way, whatever else is the very same in between the 302 and the 307 status codes.
302 Vs. 307
You might manage a redirect by means of server config files.htaccess on Apache, example.conf file on Nginx or via plugins if you are using WordPress.
In all instances, they have the exact same syntax for writing redirect rules. They vary only with commands utilized in setup files. For instance, a redirect on Apache will look like this:
Alternatives +FollowSymlinks RewriteEngine on RedirectMatch 301 ^/ oldfolder// newfolder/
(You can read about symlinks here.)
On Nginx servers, it will look like this:
rewrite ^/ oldfolder// newfolder/ permanent;
The commands utilized to inform the server’s status code of redirect and the action command differ.
- Servers status code of redirect: “301 ″ vs. “permanent.”
- Action command: “RedirectMatch” vs. “rewrite.”
But 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 enabled on your server.
Given that the most extensively spread out server type is Apache, here are examples for.htaccess apache files.
Make sure that the.htaccess file has these 2 lines above the redirect guidelines and put the guidelines below them:
Options +FollowSymlinks RewriteEngine on
Read the main documents for more information about the RewriteEngine.
To understand the examples below, you may refer to the table below on RegExp essentials.
|*||absolutely 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 Develop Redirects
How To Produce A Redirect For A Single URL
The most typical and widely used type of redirect is when deleting pages or altering URLs.
For instance, state you altered the URL from/ old-page/ to/ new-page/. The redirect rule would be:
RewriteRule ^ old-page(/? |/. *)$/ new-page/ [R=301, L] Or RedirectMatch 301 ^/ old-page(/? |/. *)$/ new-page/
The only difference in between the 2 methods is that the first utilizes the Apache mod_rewrite module, and the second usages mod_alias. It can be done utilizing both techniques.
The regular expression “^” indicates the URL must start with “/ old-page” while (/? |/. *)$ suggests that anything that follows “/ old-page/” with a slash “/” or without a specific match needs to be redirected to/ new-page/.
We could also utilize (. *), i.e., ^/ old-page(. *), however the issue is, if you have another page with a similar URL like/ old-page-other/, it will likewise be rerouted when we only wish to redirect/ old-page/.
The following URLs will match and be directed to a 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:
Reroute 301/ old-page// new-page/
Without regular expressions, all URLs with UTM inquiry string, e.g.,/ old-page? utm_source=facebook.com (which prevails considering that URLs are utilized to be shared over a social media network), would wind up as 404s.
Even/ old-page without a routing slash “/” would end up as a 404.
Redirect All Except
Let’s say we have a bunch of URLs like/ category/old-subcategory -1/,/ category/old-subcategory -2/,/ category/final-subcategory/ and want to merge all subcategories into/ category/final-subcategory/. We require the “all except” guideline here.
Otherwise, if we have some properties like “/ category/image. jpg,” it will also be redirected to “/ final-subcategory/” and cause an image break.
Directory site Modification
You can utilize the rule below if you did a classification restructuring and want to move whatever from the old directory site to the new one.
RewriteRule ^ old-directory$/ new-directory/ [R=301, NC, L] RewriteRule ^ old-directory/(. *)$/ new-directory/$1 [R=301, NC, L] I used $1 in the target to tell the server that it ought to keep in mind everything in the URL that follows/ old-directory/ (i.e.,/ old-directory/subdirectory/) and pass it (i.e., “/ subdirectory/”) onto the location. As a result, it will be rerouted to/ new-directory/subdirectory/.
I utilized 2 rules: one case without any trailing slash at the end and the other one with a trailing slash.
I could combine them into one guideline utilizing (/? |. *)$ RegExp at the end, however it would cause problems and add a “//” slash to the end of the URL when the requested URL without any tracking slash has a question string (i.e., “/ old-directory? utm_source=facebook” would be rerouted to “/ new-directory//? utm_source=facebook”).
Get rid of A Word From URL
Let’s say you have 100 URLs on your site with the city name “Chicago” and wish 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 kind http://yourwebiste.com/example/chicago/event/, then the redirect would be: RewriteRule ^(. *)/ chicago/(. *) http://% /$1/$2 [NC, R=301, L] Set A Canonical URL
Having canonical URLs is the most vital part of SEO.
If missing, you may threaten your site with duplicate content problems since online search engine treat URLs with “www” and “non-www” versions as various pages with the very same material.
For that reason, you need to guarantee you run the site just with one variation you select.
If you wish to run your website with the “www” variation, utilize this rule:
RewriteCond % ^ yourwebsite.com [NC] RewriteRule ^(. *)$ http://www.yourwebsite.com/$1 [L, R=301] For a “non-www” version: RewriteCond % HTTP_HOST ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ http://yourwebsite.com/$1 [L, R=301] Tracking slash is likewise part of canonicalization because URLs with a slash at the end or without are also dealt with differently. RewriteCond % REQUEST_FILENAME!-f RewriteRule ^(. * [^/]$/$1/ [L, R=301] This will ensure the/ example-page is rerouted to/ example-page/. You might select to remove the slash rather of including then you will require the other rule listed below: RewriteCond % REQUEST_FILENAME!-d RewriteRule ^(. *)/$/$1 [L, R=301]HTTP To HTTPS Redirect
After Google’s effort to motivate website owners to utilize SSL, migrating to HTTPS is among the typically used redirects that nearly every site has.
The rewrite guideline listed below can be utilized to require HTTPS on every site.
RewriteCond % ^ yourwebsite.com [NC, OR] RewriteCond % ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ https://www.yourwebsite.com/$1 [L, R=301, NC] Using this, you can combine a www or non-www version redirect into one HTTPS redirect rule.
Redirect From Old Domain To New
This is also among the most secondhand redirects when you choose to rebrand and require to change your domain. The rule listed below reroutes old-domain. com to new-domain. com.
RewriteCond % HTTP_HOST ^ old-domain. com$ [OR] RewriteCond % HTTP_HOST ^ 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” due to the fact that any page for historic factors might have inbound links to both versions.
The majority of website owners use WordPress and might not require a.htaccess file for redirects but use a plugin instead.
Dealing with redirects utilizing plugins might be a little various from what we discussed above. You may need to read their documents to handle RegExp properly for the particular plugin.
From the existing ones, I would suggest a complimentary plugin called Redirection, which has numerous parameters to control redirect rules and many useful docs.
Redirect Finest Practices
1. Don’t Reroute All 404 Broken URLs To The Homepage
This case often happens 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 treated as 404s.
Yeah, it’s not an excellent practice (puzzles users), and we mainly treat them as 404s anyway (they’re soft-404s), so there’s no advantage. It’s not seriously broken/bad, however extra intricacy for no excellent reason– make a better 404 page rather.
— John (@JohnMu) January 8, 2019
If you have too many pages like this, you ought to think about producing stunning 404 pages and engaging users to browse more or discover something besides what they were looking for by showing a search alternative.
It is highly suggested by Google that rerouted page content must 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 should ensure to redirect users to the appropriate page of the mobile version.
Correct: “example.com/sport/” to “m.example.com/sport/”
Incorrect: “example.com/sport/” to “m.example.com”
Likewise, you need to make sure that if one page is 404 on the desktop, it ought to likewise be 404 on mobile.
If you have no mobile variation for a page, you can prevent rerouting to the mobile version and keep them on the desktop page.
3. How To Utilize Meta Refresh
It is possible to do a redirect using a meta refresh tag like the example listed below:
If you place this tag in/ old-page/, it will reroute the user right away to/ new-page/.
Google does not prohibit this redirect, however it does not advise using it.
A meta revitalize type redirect need to just work. We don’t recommend it for 2 reasons: UX (it keeps the page in internet browser history, afaik) & processing time (we require to parse the page to see it). As soon as processed, it’s much like a redirect.
— John (@JohnMu) March 2, 2018
4. Avoid Redirect Chains
This message displays when you have a wrong routine expression setup and ends up in an infinite loop.
Screenshot by author, December 2022 Normally, this takes place when you have a redirect chain. Let’s state you redirected page 1 to page 2 a long time ago. You may have forgotten that
page 1 is rerouted and chosen to redirect page 2 to page 1 once again. As a result, you will end up with a guideline like this: RewriteRule ^ page1/ page2 [R
=301, NC, L] RewriteRule ^ page2/ page1 [R=301, NC, L] This will produce an infinite loop and produce the error revealed above. Conclusion Understanding what
redirects are and which situation needs a specific status code is fundamental to
webpages appropriately. It’s a core part of understanding SEO. Many situations require accurate knowledge of redirects, such as moving a site to a brand-new domain or creating a short-term holding page URL for a webpage that will return under its typical URL. While a lot is possible with a plugin, plugins can be misused without appropriately comprehending when and why to utilize a particular
type of redirect. More Resources: Featured Image: