sabato 6 agosto 2016

How To Redirect a Site Using .htaccess - The Easy Way

If you need to redirect a site, or a given page, to another site or to another given URL, the easiest and most powerful way is using .htaccess

Beware: .htaccess is very powerful, but it's not error-proof: even the slightest error (a missing space, or a simple dot) can result in a down of your entire site. So...
1 - make a backup of current .htaccess prior modify it;
2 - test, test, test and verify every modification

To make redirect(s) in .htaccess you have different commands:

301 Redirect (permanent)

Point to a different site or URL on a permament basis.
This is the most useful type of redirect, and it's "SEO friendly"

Examples:

Redirect permanently your entire site to another domain (new-domain.com):
Redirect 301 / http://www.new-domain.com/

Redirect permanently a certain page of your site to another page of another domain:
Redirect 301 /my-old-page/ http://www.new-domain.com/newpage/


302 redirect (temporary)

Point to a different site or URL, but only on a temporary basis (i.e., for maintenance)
The usage is the same as for Redirect 301, but you need to specify 302 instead of 301

Other types of redirect (303, 307 etc.)

There're others types of redirects, which for example have different behaviour regarding the handling of GET and POST message.
For detail about it, see Wikipedia article on the 30x redirection codes: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#3xx_Redirection

Syntax trick

You can specify "permanent" instead of "301".
So:
Redirect 301 / http://www.newdomain.com/
and
Redirect permanent / http://www.newdomain.com/
is the same command.

Using redirect for site migration

Suppose you're rebranding your site, and moving it from old-domain.com to new-domain.com
Old-domain.com is quite well indexed, with a lot of different pages well positioned in SERP, and a lot of external links pointing to them.
If you just make a full 301 redirect from old-domain.com to new-domain.com, you'll loose a lot of your positioning in SERP. But also will happen that people, arriving from external site through specific links to your site, will not find the right destination page but will get home page or, worstly, a 400 error.
You can fix the issue making a number of redirect 301 command in your .htaccess.

So you can, for example, insert in .htaccess all of following commands:

Redirect 301 /my-old-page/ http://www.new-domain.com/newpage/
Redirect 301 /index.html http://www.new-domain.com/index.php
Redirect 301 /apple.html http://www.new-domain.com/apple/index.php

You can insert as many redirect commands as you need: even hundreds of them.

How to determine what URL to redirect?

Use analytics to analyze what are the URLs of old-domain.com which receive traffic from external links or from search engine.

What about the target page?

Make the target page as similar as possible at the original page; you can use also the same text of the original page, or be sure to use the same keywords; but, and it's mostly important, the target page must be relevant as the original page, and be about the same matter (that's to say: if original page matter is "apple", you must redirect it to a page which matter is "apple" too: if the matter of the target page is "electric engine", you're wrong.
  

Nessun commento:

Posta un commento