URL Redirects For SEO: A Technical Guide

Posted by

Redirects for SEO must be utilized correctly because they affect how sites are crawled and indexed by Google.

While most people think about redirects as an internet detour indication, far more is occurring, and it’s surprisingly satisfying to discover.

Keep reading for an extensive overview of redirects and the correct application for technical SEO.

What Is A Redirect?

Site 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 to a various page to the real URL that was input or clicked.

A redirect can be set as a:

  • Temporary redirect: 302, 303, 307, 308.
  • Long-term redirect: 301.

When To Use Redirects

The primary reasons to use redirects are:

  • A private page or entire domain has been moved (URL changed).
  • To allow the usage of URL shorteners or ‘quite URLs.’
  • Site migration (e.g., HTTP to HTTPS).

For SEO purposes, URL redirects are important since they:

  • Forward authority of any links indicating a page that has moved or been erased.
  • Avoid 404 page not found mistakes (although often it is much better to leave a 404).

Redirects can be carried out on a group or domain-wide basis however often need to be set on an individual basis to avoid problems.

When utilizing RegEX for group reroutes, it can have unexpected results if your reasoning isn’t perfect!

Kinds of Redirects

There are 3 primary kinds of redirects:

  • Meta Refresh redirects are set at the page level however are generally not suggested for SEO functions. There are two kinds of meta redirect: postponed which is viewed as a momentary redirect, and immediate, which is viewed as a permanent redirect.
  • Javascript redirects are also set on the customer side’s page and can trigger SEO issues. Google has actually mentioned a preference for HTTP server-side redirects.
  • HTTP redirects are set server-side and the very best approach for SEO functions– we covered in-depth below.

What Is A HTTP Action Status Code?

Web browsers and search engine crawlers like GoogleBot are called user agents.

When a user agent attempts to access a website, what occurs is that the user agent makes a request, and the site server concerns a response.

The response is called an HTTP response status code. It provides a status for the request for a URL.

In the scenario where a user agent like GoogleBot demands a URL, the server provides a reaction.

For instance, if the ask for a URL succeeds, the server will offer a reaction code of 200, which suggests the ask for a URL succeeded.

So, when you think about a GoogleBot reaching a website and attempting to crawl it, what’s occurring is a series of demands and responses.

HTTP Reroutes

An HTTP redirect is a server response to request a URL.

If the URL exists at a different URL (because it was moved), the server informs the user representative that the URL demand is being redirected to a various URL.

The response code for a changed URL is typically in the form of a 301 or 302 reaction status code.

The entire 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 save a cache of the new URL so that the next time the old URL is asked for, it will request for the brand-new URL instead.

So, a 301 and a 302 redirect is more than an internet road indication that says, “Go here, not there.”

3XX Series Of Status Codes

Redirects are more than just the 2 status codes everyone is familiar with, the 301 and 302 reaction codes.

There are a total of seven official 3xx response status codes.

These are the various type of redirects available for use:

  • 300 Multiple Choices.
  • 301 Moved Completely.
  • 302 Found.
  • 303 See Other.
  • 304 Not Customized.
  • 305 Use Proxy.
  • 306 (Unused).
  • 307 Short-lived Redirect.
  • 308 Irreversible 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 besides 301 or 302, be sure that the intended user representative can analyze it.

Due to the fact that GoogleBot utilizes the most recent version of Chrome (called a headless web browser), it’s easy to check if a status code is compatible by examining if Chrome acknowledges the status code with a web browser compatibility list.

For SEO, one should stay with using the 301 and 302 reaction codes unless there is a particular reason to utilize one of the other codes.

301: Moved Completely

The 301 status code is consistently referenced as the 301 redirects. However the main name is 301 Moved Completely.

The 301 redirect shows to a user agent that the URL (sometimes referred to as a target resource or simply resource) was changed to another place which it ought to use the new URL for future requests.

As discussed earlier, there is more details as well.

The 301 status code also recommends to the user representative:

  • Future ask for the URL ought to be made with the new URL.
  • Whoever is making the request ought to upgrade their links to the brand-new URL.
  • Subsequent requests can be altered from GET to POST.

That last point is a technical issue. According to the main standards for the 301 status code:

“Note: For historic factors, a user representative MAY change the request method from POST to GET for the subsequent demand. If this behavior is unwanted, 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 new one.

Before making a change, you should be careful when using a 301 redirect. The 301 redirects should just be utilized when the modification to a new URL is long-term.

The 301 status code must not be used when the change is short-term.

Furthermore, if you change your mind later and return to the old URL, the old URL may not rank anymore and may take time to restore the rankings.

So, the main thing to remember is that a 301 status code will be used when the modification is long-term.

302: Found

The main thing to comprehend about the 302 status code is that it works for scenarios where a URL is briefly changed.

The meaning of this action code is that the URL is momentarily at a different URL, and it is suggested to use the old URL for future requests.

The 302 redirect status code likewise features a technical caveat associated to GET and Post:

“Keep in mind: For historic reasons, a user representative MAY change the demand method from POST to GET for the subsequent demand. If this behavior is undesirable, the 307 (Temporary Redirect) status code can be utilized rather.”

The reference to “historic factors” may describe old or buggy user agents that might change the request technique.

307: Temporary Redirect

A 307 redirect indicates the asked for URL is momentarily moved, and the user representative must utilize the original URL for future demands.

The only distinction in between a 302 and a 307 status code is that a user agent need to request the new URL with the exact same HTTP request utilized to request the original URL.

That indicates if the user agent demands the page with a GET demand, then the user agent must use a GET request for the brand-new temporary URL and can not utilize the POST demand.

The Mozilla paperwork of the 307 status code explains it more clearly than the main documentation.

“The server sends this response to direct the client to get the asked for resource at another URI with very same method that was used in the prior request.

This has the same semantics as the 302 Found HTTP reaction code, with the exception that the user agent need to not change the HTTP technique used: if a POST was used in the first request, a POST should be utilized in the 2nd request.”

Besides the 307 status code requiring subsequent requests to be of the exact same kind (POST or GET) which the 302 can go in either case, everything else is the exact same 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 same syntax for composing redirect rules. They differ only with commands used in setup files. For example, a redirect on Apache will appear like this:

Alternatives +FollowSymlinks RewriteEngine on RedirectMatch 301 ^/ oldfolder// newfolder/

(You can read about symlinks here.)

On Nginx servers, it will appear like this:

rewrite ^/ oldfolder// newfolder/ irreversible;

The commands used to tell the server’s status code of redirect and the action command differ.

For example:

  • Servers status code of redirect: “301 ″ vs. “irreversible.”
  • Action command: “RedirectMatch” vs. “reword.”

However the redirect syntax (^/ oldfolder// newfolder/) is the same for both.

On Apache, make sure that mod_rewrite and mod_alias modules (accountable for handling redirects) are allowed on your server.

Since the most commonly spread out server type is Apache, here are examples for.htaccess apache files.

Ensure that the.htaccess file has these two lines above the redirect guidelines and put the rules below them:

Choices +FollowSymlinks RewriteEngine on

Read the main paperwork to read more about the RewriteEngine.

To understand the examples below, you might describe the table below on RegExp basics.

* no or more times
+ Several times
. any single character
? Zero 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 Develop A Redirect For A Single URL

The most typical and extensively used kind of redirect is when deleting pages or changing URLs.

For instance, state you changed 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 two approaches is that the very first uses the Apache mod_rewrite module, and the second usages mod_alias. It can be done utilizing both techniques.

The routine expression “^” means the URL must start with “/ old-page” while (/? |/. *)$ suggests that anything that follows “/ old-page/” with a slash “/” or without a precise match should be rerouted to/ new-page/.

We might also use (. *), i.e., ^/ old-page(. *), however the issue is, if you have another page with a comparable URL like/ old-page-other/, it will also be rerouted when we only want to reroute/ 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 redirect any variation of the page URL to a new one. If we use redirect in the following type:

Redirect 301/ old-page// new-page/

Without routine expressions, all URLs with UTM query string, e.g.,/ old-page? utm_source=facebook.com (which is common because URLs are used to be shared over a social media), would end up as 404s.

Even/ old-page without a routing slash “/” would wind up as a 404.

Redirect All Except

Let’s state we have a lot 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 other than” rule here.

RewriteCond % !/ category/final-subcategory/ RewriteCond % REQUEST_FILENAME!-f RewriteRule ^(category/)./ category/final-subcategory/ [R=301, L] Here, we wish to redirect all under/ classification/ on the 3rd line except if it is/ category/final-subcategory/ on the 4th line. We likewise have the “!-f” rule on the second line, ignoring any file like images, CSS, or JavaScript files.

Otherwise, if we have some properties like “/ category/image. jpg,” it will also be rerouted to “/ final-subcategory/” and trigger an image break.

Directory Modification

You can utilize the guideline below if you did a category restructuring and wish to move everything from the old directory 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 tell the server that it must remember 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 redirected to/ new-directory/subdirectory/.

I utilized two guidelines: one case with no 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, but it would trigger issues and include a “//” slash to the end of the URL when the asked for URL without any routing slash has a query 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 website 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://% SERVER_NAME/$1-$2 [NC, R=301, L] If the example URL is in the type 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 important part of SEO.

If missing, you may threaten your website with duplicate content issues since online search engine deal with URLs with “www” and “non-www” versions as various pages with the same material.

Therefore, you need to ensure you run the site just with one version you select.

If you wish to run your site with the “www” version, use this rule:

RewriteCond % ^ yourwebsite.com [NC] RewriteRule ^(. *)$ http://www.yourwebsite.com/$1 [L, R=301] For a “non-www” variation: RewriteCond % ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ http://yourwebsite.com/$1 [L, R=301] Tracking slash is likewise part of canonicalization since URLs with a slash at the end or without are also treated differently. RewriteCond % !-f RewriteRule ^(. * [^/]$/$1/ [L, R=301] This will make certain the/ example-page is rerouted to/ example-page/. You might pick to get rid of the slash instead of including then you will need the other guideline listed below: RewriteCond % !-d RewriteRule ^(. *)/$/$1 [L, R=301]HTTP To HTTPS Redirect

After Google’s effort to motivate site owners to use SSL, migrating to HTTPS is one of the typically used redirects that nearly every site has.

The rewrite rule listed below can be used to force HTTPS on every site.

RewriteCond % HTTP_HOST ^ yourwebsite.com [NC, OR] RewriteCond % HTTP_HOST ^ www.yourwebsite.com [NC] RewriteRule ^(. *)$ https://www.yourwebsite.com/$1 [L, R=301, NC] Utilizing this, you can combine a www or non-www version reroute into one HTTPS redirect guideline.

Redirect From Old Domain To New

This is likewise one of the most secondhand redirects when you decide to rebrand and need to change your domain. The rule below redirects 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 2 cases: one with the “www” version of URLs and another “non-www” since any page for historical factors might have inbound links to both versions.

Many website owners utilize WordPress and may not need a.htaccess file for redirects but use a plugin instead.

Dealing with redirects utilizing plugins might be a little various from what we talked about above. You may require to read their documentation to deal with RegExp properly for the particular plugin.

From the existing ones, I would advise a complimentary plugin called Redirection, which has numerous specifications to manage redirect rules and numerous helpful docs.

Redirect Finest Practices

1. Don’t Redirect All 404 Broken URLs To The Homepage

This case frequently takes place when you are too lazy to examine your 404 URLs and map them to the appropriate landing page.

According to Google, they are still all treated as 404s.

If you have too many pages like this, you need to think about developing gorgeous 404 pages and engaging users to search additional or find something aside from what they were searching for by showing a search option.

It is highly recommended by Google that redirected page material need to be comparable to the old page. Otherwise, such a redirect may be thought about a soft 404, and you will lose the rank of that page.

2. Get Mobile Page-Specific Redirects Right

If you have different URLs for desktop and mobile sites (i.e., “example.com” for desktop and “m.example.com” for mobile), you need to make certain to reroute users to the appropriate page of the mobile variation.

Correct: “example.com/sport/” to “m.example.com/sport/”
Wrong: “example.com/sport/” to “m.example.com”

Likewise, you have 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 version 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 instantly to/ new-page/.

Google does not restrict this redirect, however it does not advise using it.

According to John Mueller, search engines may not be able to acknowledge that type of redirect correctly. The very same is also real about JavaScript redirects.

4. Avoid Redirect Chains

This message shows when you have an incorrect routine expression setup and winds up in a boundless loop.

Screenshot by author, December 2022 Typically, this takes place when you have a redirect chain. Let’s state you rerouted page 1 to page 2 a long period of time earlier. You might have forgotten that

page 1 is redirected and chosen to redirect page 2 to page 1 once again. As an outcome, 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 a boundless loop and produce the error shown above. Conclusion Understanding what

redirects are and which circumstance requires a particular status code is fundamental to

enhancing

webpages appropriately. It’s a core part of comprehending SEO. Numerous scenarios need accurate knowledge of redirects, such as migrating a website to a brand-new domain or producing a short-lived holding page URL for a web page that will return under its regular URL. While a lot is possible with a plugin, plugins can be misused without appropriately understanding when and why to utilize a specific

type of redirect. More Resources: Included Image: