[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 05-10-2007, 02:22 AM   #1 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Location: Noida, India
Posts: 231
229.50 NP$ (Donate)

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, 04:00 AM   #2 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 760
56.85 NP$ (Donate)

JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice


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.

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
Selling :
19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM
JFS is offline  
Old 05-10-2007, 04:20 AM   #3 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Location: Noida, India
Posts: 231
229.50 NP$ (Donate)

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, 06:36 AM   #4 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 760
56.85 NP$ (Donate)

JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice


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
Selling :
19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM
JFS is offline  
Old 05-10-2007, 06:39 AM   #5 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Location: Noida, India
Posts: 231
229.50 NP$ (Donate)

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 07:03 AM.
iPlox is offline  
Old 05-10-2007, 08:09 AM   #6 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 760
56.85 NP$ (Donate)

JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice


301 is via htaccess, i don't know how to do it, maybe someone else can help you with that.
__________________
Joćo Fernandes Silva
Selling :
19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM
JFS is offline  
Old 05-10-2007, 11:55 AM   #7 (permalink)
Stud Sausage
 
Join Date: Dec 2006
Location: England
Posts: 1,546
34.41 NP$ (Donate)

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]

Matt
__________________
My NamePros Tools
(firefox plugin, google gadget etc)
Matthew. is offline  
Old 05-10-2007, 03:29 PM   #8 (permalink)
JFS
NamePros Regular
 
JFS's Avatar
 
Join Date: Oct 2005
Location: Portugal
Posts: 760
56.85 NP$ (Donate)

JFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really niceJFS is just really nice


yes, agreed, via htaccess is better, but since i'm not very confortable at it i gave a quick answer.
__________________
Joćo Fernandes Silva
Selling :
19P.ORG - ARCADEHITS.ORG - AZIAN.NET - COREFANS.COM - CTUTORIALS.NET - DEDISEEK.COM - HITCHECK.COM - HOST15.COM - HOSTCUSTOMER.COM - LARGETIPS.COM - SCRIPTCANDY.COM - VISUALBOOK.NET - VOXVPS.COM / .NET - WALLPAPERSARENA.COM
JFS is offline  
Closed Thread


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 07:20 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85