| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: Noida, India
Posts: 231
![]() ![]() | 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 |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Oct 2005 Location: Portugal
Posts: 800
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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");
?> ????: 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 |
| |
| | #4 (permalink) |
| NamePros Regular Join Date: Oct 2005 Location: Portugal
Posts: 800
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Regular Join Date: Mar 2006 Location: Noida, India
Posts: 231
![]() ![]() | 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.
|
| |
| | #7 (permalink) |
| Senior Member Join Date: Dec 2006 Location: England
Posts: 1,568
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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: PHP Code: 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 |
| |