There are several reasons to use URL redirection:
- Moving a old site to new domain
- URL Shortening
- Mis-type a URL
- Search Engine Manipulation ( Canonical )
- Manipulating visitors
The HTTP standard defines several status codes for redirection methods:
- 300 – multiple choices redirection
- 301 – moved permanently
- 302 – temporary redirect ( used to specify redirection for unspecified reason)
- 307 – temporary redirect
Redirect using .htaccess :
Redirect to old Domain website to new domain website:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.:]+.)*olddomain.com.?(:[0-9]*)?$ [NC]
RewriteRule ^(.*)$ [R=301,L]
———————————————————————————————–
301 Redirection from www to non-www site:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^domain.com
RewriteRule (.*) [R=301,L]
———————————————————————————————–
301 Redirection from non-www to www site:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ [L,R=301]
———————————————————————————————–
Now Google provides the solutions for canonical issues for adding meta tag,
<link rel=”canonical” href=”http://www.preferreddomain.com”>
Moving a old site to new domain
URL Shortening
Mis-type a URL
Search Engine Manipulation
Manipulating visitors