Unstoppable Domains โ€” AI Assistant

Redirecting to a Sub-Domain

Spacemail by SpaceshipSpacemail by Spaceship
Watch

iPlox

Established Member
Impact
0
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
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
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/ )
 
0
•••
That's a great help, thanks. I was wondering if something could do:

abc.com/blabla/whateverhere

to

abc.xyz.com/blabla/whateverhere

?
 
0
•••
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
 
0
•••
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:
0
•••
301 is via htaccess, i don't know how to do it, maybe someone else can help you with that.
 
0
•••
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:
header('HTTP/1.1 301 Moved Permanently');

So your code becomes...
PHP:
<?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
 
0
•••
yes, agreed, via htaccess is better, but since i'm not very confortable at it i gave a quick answer.
 
0
•••
CatchedCatched
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomainEasy โ€” Live Options
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back