Zend - The PHP Company




HTTP

Add Code


Sub-Domain Redirect/WorkAround  

Type: code fragment
Added by: Plove
Entered: 09/11/2001
Last modified: 01/11/2000
Rating: - (fewer than 3 votes)
Views: 5490
This will allow your users to be redirected according to wub-doamin prefix.


<?
//===============================\ 
//  Author:Patrick Loven         \ 
//  Name: Sub-Domain Redirect    \ 
//  Date: 11/09/01               \ 
//  Site: www.lovenresources.com \ 
//===============================\ 

/*------------------------------------------------------------------------\
There are 2 ways of doing this, static and dynamic(for those few fortunate
enough to allow wildcard sub-domians). In either case, your isp must allow
sub-domains, and add them for you.

Static - This is setup to pass the user directly to the folder you want
based on the pre in the pre.domain.ltd. If criteria is passed, they will
be forwarded to the specified folder.
  i.e. : search.domain.com => search.domain.com/search/
  
Dynamic - This is setup to pass the user to a dynamic "pre named folder"(i.e
users/whatever_dynamic),based on the pre in the pre.domain.ltd. If criteria
is passed, they will be forwarded to the specified folder.
  i.e. : whatever.domain.com  => domain.com/users/whatever/
       whatever2.domain.com => domain.com/users/whatever2/
//------------------------------------------------------------------------*/

$where explode(".",$HTTP_HOST);
$default = ("yourstartpage.xxx");

/* Static
if($where[0] == "whatever1"){
    header("Location:http://$HTTP_HOST/whatever1/");
}elseif($where[0] == "whatever2"){
    header("Location:http://$HTTP_HOST/whatever2/");
}else{
    header("Location:http://$HTTP_HOST/$default");
}
*/

// Dynamic
if(is_dir("$DOCUMENT_ROOT/$where[0]")){
    
header("Location:http://$HTTP_HOST/$where[0]");
}else{
    
header("Location:http//$HTTP_HOST/$default");
}
?>


Usage Example


see code


Rate This Script





Search



This Category All Categories