A little help with php for a redirect

zaboss

Perch
Hi,

i have a site that I need to move from www.domain.tld to subdomain.domain.tld. The site is getting many hits from google and other search engines which under the new circumstances would reach to a 404. So I need to make a 404 page that would redirect the visitor to the right pages. The new subdomaind would match exactly the present domain while the domain would have a different content. Since the domain site is in php, but I am not very good with it (I'm a windows person) and it's on a windows server I ask you for a little helpt with the needed code so if one is looking for www.domain.tld/index.php?itemid=NNN to be redirected to subdomain.domain.tld/index.php?itemid=NNN.

Thank you.
 
Maybe something like this?

PHP:
header("Location: http://subdomain.domain.tld/index.php?itemid=NNN");

If you want this to work on all pages, you can try this (though I never tried it myself):

PHP:
header("Location: http://subdomain.".$_SERVER['PHP_SELF']."");

Test the last one first, as I just made it up.
 
Not sure. Just need something to grab the part after the www of the url and add to it subdomain name and redirect to this new created url.
 
Here's a 404.php page I created for a site for similar purposes. In the cp I set this page to be my 404 error handler. If you go to www.olddomain.com/somepage.ext you are redirected to www.newdomain.com/somepage.ext

PHP:
<?php
if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '') {
  header('location:http://www.olddomain.com'.$_SERVER['REQUEST_URI']);
} else {
  header('location:http://www.newdomain.com/');
}
die();
?>

I have this code running on a Linux server here at Jodo. I haven't tested on Windows/IIS.

Tim
 
Back
Top