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.
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.
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:
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.
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/“ />
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]
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:
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
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]
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]
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]
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 – 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.
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.