8-7 Mon-Sat   (509) 491 8580

Redirects explained

What is a redirect?

Redirects explained, we hear ‘what is a redirect?’ daily! A Redirect is a way to redirect site users and search engines to a different URL than the one they originally requested. Here is Googles two cents.

The following are descriptions and examples of some of the most commonly used redirects.

301 – Moved Permanently

A 301 redirect, is a permanent redirect, which transfers about 90-99% of link rating. This redirect indicates that the page has been moved to a new address and the old URL should be considered out-of-date.

302 – Found (HTTP 1.1) / Moved Temporarily (HTTP 1.0)

A 302 redirect,  or temporary redirect. This redirect transmits 0% of a links rating and, in most cases, should not be used.

The Internet works under the HTTP protocol, which determines how to manage URLs. In two versions of this protocol, this server reply has a different response status:

  • HTTP 1.0: 302 server response is “Moved Temporarily” – the current document is temporarily moved to a different URL.
  • HTTP 1.1: there was a change in the server’s response to “Found” – the current document was found.

307 – Moved Temporarily (HTTP 1.1 Only)

307 redirect in the HTTP 1.1 protocol became the receiver of the 302 redirect. While the main search bots will consider it as an analog-302, for almost all cases, it’s best to use 301.

Other redirects

There are also other kinds of redirects: using Meta Refresh or JavaScript – which are executed at the page level, and not at the server level. Here’s what a typical Meta Refresh redirect looks like:

<meta http-equiv=refresh content=5;url=http://example.com/ />

To force a domain from www to non www:

RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

Force page from non www to www:

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

 

Slash canonicalization at the end of the URL

It is also important to decide on the format using the slash at the end of the URL, As a search engine will see 2 URLs:

  • http://www.example.com/folder1/
  • http://www.example.com/folder1

Therefore decided on which to use, and choose the following redirects

To remove a slash at the end:

RewriteCond %{HTTP_HOST} (.*)
RewriteCond %{REQUEST_URI} /$ [NC]
RewriteRule ^(.*)(/)$ $ 1 [L,R =301]

To add a slash to the end of the address bar:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]

Redirection of one page to another page:

Redirect 301 /oldpage.html http://www.example.com/newpage.html

Redirect the duplicates of your main page:

This redirect code ensures your home page address includes multiple versions of direct links.

For example, default.htm or index.html, will be redirected to the canonical homepage, http://www.example.com:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index|main)\.(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://www.example.com/$1 [L,R=301]

Redirect directory

If the directory structure displayed in the URL, and you need a redirect, you will  need the following redirect:

RewriteRule ^(.*)/old-folder/(.*)$ $1/new-folder/$2 [R=301,L]

But, if the URL of the old folder starts immediately after the domain: www.site.com/old-folder/, then you need to use the following code.

RewriteRule old-folder /(.*) / old-folder /$1 [R=301,L]

Remove multiple slashes / or dashes in a URL

Sometimes a URL will include several slashes, for example, www.example.com/folder////page-1.html. Here it is necessary to do 301 redirect per page with one slasher www.example.com/folder/page-1.html:

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]

Likewise, you can put together several dashes into one in the URL: from www.example.com/folder/page-1.html at www.example.com/folder/page-1.html:

RewriteCond %{REQUEST_URI} ^(.*)--(.*)$
RewriteRule . %1-%2 [R=301,L]

Move to a new domain. A strategy for 301 redirects.

RewriteCond %{REQUEST_FILENAME} robots.txt$ [NC]
RewriteRule ^([^/]+) $1 [L]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

and the robots.txt file for the old site:

User-agent: Google
Disallow:
Host: newsite.com

301 redirect vs. Canonical

301 – Hey, Search Engine spider: My page is no longer here,  it has moved to a new page. Please delete the old page from your index and transfer its link ranking to a new page.

Canonical – Hey, Search Engine Spider : I have several versions of this page, please, only index the version of the page that is canonical. I will keep other pages accessible, so people can see them, but do not include them in your index and please transfer the link ranking to this preferred page.

In review, both options allow keeping the link ranking and they will be interpreted similarly by Google. However, in general, 301-redirect is the preferred method.

Mistakes in redirects

Any multi-step redirect. If possible, do not allow multi-step redirects..

Using the wrong type of redirects. When choosing the type of redirect, it is necessary to take into account the differences of each of them.

Implementation check. After performing any redirect on your site, you need to check that it works!

If you need help with redirects or redirects explained in more detail call us.