URL Redirects For SEO: A Technical Guide

Posted by

Redirects for SEO must be used properly since they impact how sites are crawled and indexed by Google.

While the majority of people think of redirects as a web detour indication, much more is occurring, and it’s surprisingly enjoyable to discover.

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

What Is A Redirect?

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

A redirect can be set as a:

  • Momentary redirect: 302, 303, 307, 308.
  • Permanent redirect: 301.

When To Utilize Redirects

The main reasons to utilize redirects are:

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

For SEO purposes, URL redirects are very important due to the fact that they:

  • Forward authority of any links indicating a page that has moved or been deleted.
  • Prevent 404 page not discovered errors (although sometimes it is better to leave a 404).

Redirects can be implemented on a group or domain-wide basis but often need to be set on a specific basis to prevent concerns.

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

Types Of Redirects

There are 3 main kinds of redirects:

  • Meta Refresh redirects are set at the page level however are generally not suggested for SEO purposes. There are two types of meta redirect: delayed which is seen as a short-term redirect, and immediate, which is viewed as a permanent redirect.
  • Javascript reroutes are also set on the client side’s page and can trigger SEO problems. Google has mentioned a choice for HTTP server-side redirects.
  • HTTP redirects are set server-side and the very best approach for SEO purposes– we covered in-depth listed below.

What Is A HTTP Response Status Code?

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

When a user representative attempts to access a web page, what occurs is that the user representative makes a request, and the site server concerns a reaction.

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

In the scenario where a user agent like GoogleBot requests a URL, the server provides an action.

For example, if the ask for a URL achieves success, the server will offer a reaction code of 200, which means the ask for a URL succeeded.

So, when you think about a GoogleBot reaching a site and attempting to crawl it, what’s taking place is a series of requests and reactions.

HTTP Reroutes

An HTTP redirect is a server reaction 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 request is being redirected to a various URL.

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

The whole 3xx series of reaction codes interact much details that can additionally be acted upon by the user representative.

An example of an action that the user agent can take is to conserve a cache of the new URL so that the next time the old URL is requested, it will request the brand-new URL instead.

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

3XX Series Of Status Codes

Redirects are more than just the 2 status codes everybody recognizes with, the 301 and 302 action codes.

There are an overall of 7 official 3xx reaction status codes.

These are the various kinds of redirects readily available for use:

  • 300 Multiple Choices.
  • 301 Moved Completely.
  • 302 Found.
  • 303 See Other.
  • 304 Not Modified.
  • 305 Use Proxy.
  • 306 (Unused).
  • 307 Momentary Redirect.
  • 308 Permanent Redirect.

A few of the above status codes have not been around as long and might not be used. So, prior to using any redirect code other than 301 or 302, make sure that the designated user representative can translate it.

Because GoogleBot uses the current variation of Chrome (called a headless web browser), it’s simple to inspect if a status code works by checking if Chrome acknowledges the status code with a browser compatibility list.

For SEO, one should stick to utilizing the 301 and 302 response codes unless there is a specific factor to use among the other codes.

301: Moved Completely

The 301 status code is consistently referenced as the 301 redirects. But the main name is 301 Moved Permanently.

The 301 redirect suggests to a user agent that the URL (often referred to as a target resource or just resource) was changed to another area which it ought to utilize the brand-new URL for future demands.

As discussed earlier, there is more info also.

The 301 status code likewise suggests to the user representative:

  • Future requests for the URL need to be made with the brand-new URL.
  • Whoever is making the demand should upgrade their links to the brand-new URL.
  • Subsequent demands can be altered from GET to POST.

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

“Note: For historical reasons, a user agent MAY alter the demand method from POST to GET for the subsequent request. If this habits is unwanted, the 308 (Long-term Redirect) status code can be utilized rather.”

For SEO, when online search engine see a 301 redirect, they pass the old page’s ranking to the new one.

Prior to making a change, you must beware when using a 301 redirect. The 301 redirects should only be used when the modification to a brand-new URL is irreversible.

The 301 status code must not be utilized when the change is temporary.

In addition, if you alter your mind later and go back to the old URL, the old URL might not rank any longer and might require time to restore the rankings.

So, the main thing to bear in mind is that a 301 status code will be utilized when the change is irreversible.

302: Found

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

The meaning of this reaction code is that the URL is momentarily at a different URL, and it is recommended to utilize the old URL for future requests.

The 302 redirect status code also comes with a technical caution associated to GET and Post:

“Note: For historic reasons, a user representative MAY change the request method from POST to GET for the subsequent demand. If this behavior is unwanted, the 307 (Momentary Redirect) status code can be used rather.”

The reference to “historic factors” might describe old or buggy user agents that might alter the request approach.

307: Temporary Redirect

A 307 redirect indicates the asked for URL is briefly moved, and the user representative must utilize the initial URL for future requests.

The only difference between a 302 and a 307 status code is that a user agent must request the new URL with the very same HTTP request utilized to request the initial URL.

That indicates if the user representative requests the page with a GET request, then the user representative need to use a GET ask for the new momentary URL and can not use the POST request.

The Mozilla documents of the 307 status code discusses it more plainly than the main documentation.

“The server sends this reaction to direct the customer to get the asked for resource at another URI with same technique that was used in the previous request.

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

Other than the 307 status code requiring subsequent demands to be of the very same kind (POST or GET) and that the 302 can go in any case, everything else is the exact same in between the 302 and the 307 status codes.

302 Vs. 307

You might deal with a redirect via server config files.htaccess on Apache, example.conf file on Nginx or through plugins if you are utilizing WordPress.

In all instances, they have the very same syntax for composing redirect rules. They vary only with commands utilized in configuration files. For instance, a redirect on Apache will appear like this:

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

(You can check out symlinks here.)

On Nginx servers, it will appear like this:

rewrite ^/ oldfolder// newfolder/ permanent;

The commands utilized to inform the server’s status code of redirect and the action command vary.

For example:

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

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

On Apache, ensure that mod_rewrite and mod_alias modules (responsible for managing redirects) are made it possible for on your server.

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

Make sure that the.htaccess file has these two lines above the redirect rules and put the rules listed below them:

Options +FollowSymlinks RewriteEngine on

Read the official documentation to read more about the RewriteEngine.

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

* absolutely no or more times
+ Several times
. any single character
? Absolutely no or one time
^ Start of the string
$ End of the string
| b OR operadn” |” a or b
(z) keeps in mind the match to be used when calling $1

How To Create Redirects

How To Develop A Redirect For A Single URL

The most common and extensively utilized kind of redirect is when deleting pages or altering URLs.

For instance, say 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 distinction between the 2 techniques is that the very first utilizes the Apache mod_rewrite module, and the second uses mod_alias. It can be done utilizing both approaches.

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

We could likewise utilize (. *), i.e., ^/ old-page(. *), however the issue is, if you have another page with a similar URL like/ old-page-other/, it will also 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 redirect any variation of the page URL to a brand-new one. If we utilize redirect in the list below form:

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

Without regular expressions, all URLs with UTM query string, e.g.,/ old-page? utm_source=facebook.com (which prevails given that URLs are utilized to be shared over a social network), would wind up as 404s.

Even/ old-page without a routing slash “/” would wind 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 wish to combine all subcategories into/ category/final-subcategory/. We need the “all except” rule here.

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

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

Directory site Modification

You can utilize the guideline below if you did a category 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 utilized $1 in the target to inform the server that it should remember everything in the URL that follows/ old-directory/ (i.e.,/ old-directory/subdirectory/) and pass it (i.e., “/ subdirectory/”) onto the destination. As an outcome, it will be redirected to/ new-directory/subdirectory/.

I utilized 2 rules: one case without any trailing slash at the end and the other one with a routing slash.

I could combine them into one rule utilizing (/? |. *)$ RegExp at the end, however it would cause problems and add a “//” slash to the end of the URL when the asked for URL without any routing slash has an inquiry string (i.e., “/ old-directory? utm_source=facebook” would be redirected 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://% SERVER_NAME/$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://% SERVER_NAME/$1/$2 [NC, R=301, L] Set A Canonical URL

Having canonical URLs is the most vital part of SEO.

If missing out on, you might endanger your site with duplicate content problems because search engines deal with URLs with “www” and “non-www” versions as different pages with the very same material.

Therefore, you must ensure you run the website just with one variation you pick.

If you wish to run your website with the “www” variation, utilize this rule:

RewriteCond % HTTP_HOST ^ 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 considering that URLs with a slash at the end or without are likewise treated in a different way. RewriteCond % REQUEST_FILENAME!-f RewriteRule ^(. * [^/]$/$1/ [L, R=301] This will ensure the/ example-page is rerouted to/ example-page/. You may pick to remove the slash rather of including then you will require the other rule below: RewriteCond % !-d RewriteRule ^(. *)/$/$1 [L, R=301]HTTP To HTTPS Redirect

After Google’s initiative to motivate website owners to use SSL, migrating to HTTPS is one of the frequently used redirects that practically every site has.

The rewrite rule below can be utilized to force HTTPS on every website.

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 guideline.

Redirect From Old Domain To New

This is likewise among the most pre-owned redirects when you decide to rebrand and need 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 uses 2 cases: one with the “www” version of URLs and another “non-www” because any page for historical reasons may have incoming links to both versions.

The majority of site owners use WordPress and may not need a.htaccess apply for redirects however utilize a plugin rather.

Dealing with redirects utilizing plugins may be slightly different from what we talked about above. You might need to read their documents to manage RegExp properly for the specific plugin.

From the existing ones, I would suggest a totally free plugin called Redirection, which has numerous criteria to manage redirect guidelines and numerous helpful docs.

Reroute Finest Practices

1. Do not Reroute All 404 Broken URLs To The Homepage

This case typically 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 must think about producing beautiful 404 pages and engaging users to search more or find something besides what they were trying to find by showing a search option.

It is highly advised by Google that redirected page material need to be comparable to the old page. Otherwise, such a redirect may 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 make certain to redirect users to the appropriate page of the mobile variation.

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

Also, you have to guarantee that if one page is 404 on the desktop, it should likewise be 404 on mobile.

If you have no mobile version for a page, you can avoid redirecting 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 reroute the user instantly to/ new-page/.

Google does not prohibit this redirect, but it does not recommend using it.

According to John Mueller, online search engine may not be able to acknowledge that kind of redirect correctly. The same is likewise true about JavaScript reroutes.

4. Prevent Redirect Chains

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

Screenshot by author, December 2022 Generally, this occurs when you have a redirect chain. Let’s state you redirected page 1 to page 2 a long time earlier. You might have forgotten that

page 1 is redirected and chosen to reroute page 2 to page 1 again. As a result, 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 produce a boundless loop and produce the mistake shown above. Conclusion Knowing what

redirects are and which circumstance needs a particular status code is basic to

optimizing

webpages correctly. It’s a core part of understanding SEO. Many scenarios require accurate knowledge of redirects, such as migrating a site to a new domain or producing a short-term holding page URL for a webpage that will return under its regular URL. While so much is possible with a plugin, plugins can be misused without effectively comprehending when and why to use a particular

type of redirect. More Resources: Featured Image: