birmingham@ic.fbi.gov , phoenix@ic.fbi.gov , fbise@leo.gov
NickSoft Linux Cookbook Index NickSoft Linux Cookbook
Quick howto's, Real live examples.
 
 FAQFAQ   SearchSearch   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


301 Redirect - domain.com->www.domain.com and ip->doma

 
Post new topic   Reply to topic    NickSoft Linux Cookbook Index -> Apache
View previous topic :: View next topic  
Author Message
NickSoft
Site Admin


Joined: 13 Nov 2006
Posts: 22

PostPosted: Mon Nov 27, 2006 8:29 pm    Post subject: 301 Redirect - domain.com->www.domain.com and ip->doma Reply with quote

Using http redirect (code 301 - Moved Permanently) is useful because search engines gives negative credits for using multiple domains on the same site (mirror sites doesn't count).
Other issue is when you have domain "examle.com" and both "example.com" and "www.example.com" are valid. Most of you know that one of factors that search engines use to assess site importance is so called back-links. However some site link to "example.com" and other to "www.example.com". This way search engine rankings will be divided between "www.example.com" and "example.com". If you redirect one domain to the other using 301 redirect search engine will give all credits to it.

Here is how to prepare virtual hosts for redirection:
Code:

namevirtualhost *:80

#set up an alias virtual host:
<VirtualHost *:80>
  DocumentRoot "/webroot/301redirect"
  ServerName 72.21.34.34
  ServerAlias 72.21.34.35
#we want to point sitealias.com to realsite.com
  ServerAlias sitealias.com
#realsite.com will redirect to www.realsite.com
  ServerAlias realsite.com
# put here other aliases if you need to

  DirectoryIndex index.php index.html

#  put CustomLog if you need to log redirects
  <Directory "/webroot/301redirect">
    AllowOverride AuthConfig Indexes Limit Options
    Options Indexes FollowSymlinks MultiViews

    RewriteEngine On
    RewriteRule ^(.*)$  index.php

    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>

#this is virutal host for www.realsite.com
<VirtualHost *:80>
  DocumentRoot "/webroot/realsite"
  ServerName www.realsite.com

  <Directory "/webroot/realsite">
    AllowOverride AuthConfig Indexes Limit Options FileInfo
    Options Indexes FollowSymlinks MultiViews

#put here your site configuration

    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>


put one file in /webroot/301redirect called index.php:
Code:

<?
$uri=$_SERVER["REQUEST_URI"];
if($uri=='')$uri='/';
$url='http://www.'.($_SERVER['HTTP_HOST']).$uri;
switch($HTTP_HOST){
  case '72.21.34.34': $host='www.layeredtech.com'; break;
  case 'sitealias.com': $host='www.realsite.com'; break;
// put here other aliases
  default: $host="www.$HTTP_HOST";
}
$url="http://$host$uri";
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: '.$url);
exit;
?>


to add new ip address or site you must:
1. add it to first virtual host as alias:
Code:
ServerAlias 72.21.34.36

2. add it to index.php:
Code:
case '72.21.34.36': $host='www.layeredtech.com'; break;


to redirect mysite.com to www.mysite.com you must:
1. add it as alias in first virtual host:
Code:
 ServerAlias mysite.com

2. you DON'T need to add it to index.php - To put www. before host is default action for redirection virtual host
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    NickSoft Linux Cookbook Index -> Apache All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




MLDb.org Magic Eight Ball Croler Web Search Croler Web Directory Bianca Ryan MyBestMatch.net Microlab.info Digger Services Sofia

Powered by 220V

AbuseIPDB Contributor Badge