NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Redirecting to a Sub-Domain

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-10-2007, 03:22 AM THREAD STARTER               #1 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: Noida, India
Posts: 231
iPlox will become famous soon enoughiPlox will become famous soon enough
 



Redirecting to a Sub-Domain


I have a wordpress based website originally at some domain abc.com which i want to move to a subdomain abc.xyz.com . I have already set up a mirror at abc.xyz.com so I wanted to know if there was a way to redirect (301) every page on abc.com to the corresponding page on abc.xyz.com ?

Thanks,
Abhinav
iPlox is offline  
Old 05-10-2007, 05:00 AM   #2 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



you have 2 choices, or you do with mod_rewrite from apache or you can eventually use php.

put this on a index page on your "abc.com" ( index.php )
Code:
<?php
// sets the new domain
$new_domain= "http://www.google.com/";

// gets the corrent requested url
$old_url = $_SERVER['REQUEST_URI'];

// the redirect part
header("Location: $new_domain.$old_url");

 ?>
i'm assuming that the url's are the same and only the domain is diferent, that's what i understand from your message.
????: NamePros.com http://www.namepros.com/programming/326230-redirecting-to-a-sub-domain.html

hope this helps ( if you wanna try it go to http://www.egek.com/teste/ and it will redirect you to http://www.google.com/teste/ )
__________________
Joćo Fernandes Silva
JFS is offline  
Old 05-10-2007, 05:20 AM THREAD STARTER               #3 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: Noida, India
Posts: 231
iPlox will become famous soon enoughiPlox will become famous soon enough
 



That's a great help, thanks. I was wondering if something could do:

abc.com/blabla/whateverhere

to

abc.xyz.com/blabla/whateverhere

?
iPlox is offline  
Old 05-10-2007, 07:36 AM   #4 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



that code does that...

just change the
$new_domain= "http://www.google.com/";
to
$new_domain= "http://abc.xyz.com/";


and

abc.com/anything_here
will go to
abc.xyz.com/anything_here
__________________
Joćo Fernandes Silva
JFS is offline  
Old 05-10-2007, 07:39 AM THREAD STARTER               #5 (permalink)
NamePros Regular
Join Date: Mar 2006
Location: Noida, India
Posts: 231
iPlox will become famous soon enoughiPlox will become famous soon enough
 



Ok, excellent, I didnt notice that alteration in the last line. Thanks a lot!!

Just one last question, can this be modified to do a 301 permanant redirect, or does it already do so?
Last edited by iPlox; 05-10-2007 at 08:03 AM.
iPlox is offline  
Old 05-10-2007, 09:09 AM   #6 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



301 is via htaccess, i don't know how to do it, maybe someone else can help you with that.
__________________
Joćo Fernandes Silva
JFS is offline  
Old 05-10-2007, 12:55 PM   #7 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
I would have suggested an all .htaccess approach (mod_rewrite), however since you seem to have settled into php already

You can use the header functions to modify headers sent, i.e. you can achieve the same effect as a 301 redirect using it.

PHP Code:
header('HTTP/1.1 301 Moved Permanently'); 
So your code becomes...
PHP Code:
<?php
header
('HTTP/1.1 301 Moved Permanently');

$new_domain"http://abz.xzy.com/";
$old_url $_SERVER['REQUEST_URI'];

header('Location: ' $new_domain $old_url);
?>

My, arguably better answer to this would be: (in .htaccess)
Code:
RewriteEngine On
RewriteRule ^(.*)$ http://abc.xyz.com/$1 [R=301,L]

????: NamePros.com http://www.namepros.com/showthread.php?t=326230
Matt
Matthew. is offline  
Old 05-10-2007, 04:29 PM   #8 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
Join Date: Oct 2005
Location: Portugal
Posts: 800
JFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to allJFS is a name known to all
 



yes, agreed, via htaccess is better, but since i'm not very confortable at it i gave a quick answer.
__________________
Joćo Fernandes Silva
JFS is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 03:27 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger