Posted By

RM on 04/02/10


Tagged

redirect google domain friendly


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

wirenaught


Google friendly domain redirect


 / Published in: HTML
 

URL: http://www.webtoolkit.info/google-friendly-domain-redirect-using-apache-rewrite.html

You must use Google friendly domain redirect in these cases: You changed a domain name for your web page and want the old one to redirect visitors to a new one. You have many domains for your website (one primary and many alternative). You want to strip the ‘www’ part from the domain name.

How to redirect? For case #1 and #2 you must point (alias) all the domains to the same website. Ask your server administrator or hosting providers how to do that. Some times hosting providers call this – domain parking. Select configuration for desired case below. Replace domain names with your real ones and paste the code to file named ‘.htaccess’. Upload the file it into the root folder of your web page.

  1. Configuration for case #1
  2.  
  3. RewriteEngine On
  4. RewriteBase /
  5.  
  6. # redirects old domain to a new one
  7. RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
  8. RewriteRule ^.*$ http://www.newdomain.com%{REQUEST_URI} [R=301,L]
  9.  
  10.  
  11.  
  12.  
  13.  
  14. Configuration for case #2
  15.  
  16. RewriteEngine On
  17. RewriteBase /
  18.  
  19. # redirects any alternative domain which name isn't "www.primarydomain.com"
  20. RewriteCond %{HTTP_HOST} !^www\.primarydomain\.com$
  21. RewriteRule ^.*$ http://www.primarydomain.com%{REQUEST_URI} [R=301,L]
  22.  
  23.  
  24.  
  25.  
  26.  
  27. Configuration for case #3
  28.  
  29. RewriteEngine On
  30. RewriteBase /
  31.  
  32. # strips the "www"
  33. RewriteCond %{HTTP_HOST} ^www\.domain\.com$
  34. RewriteRule ^.*$ http://domain.com%{REQUEST_URI} [R=301,L]

Report this snippet  

You need to login to post a comment.