View Full Version : [PHP] Redirect forumpages to new domain
Peo
December 19th, 2004, 13:44
At another site I run I have recently moved a forum from one domain to a new domain. I now need a redirect from the old location of the threads to the new location.
For instance:
the old
bio.nu/forum/index.php?showtopic=581
should redirect to the new location
filmsnack.se/index.php?showtopic=581
All forumpages are located at index.php so all the php file has to do is replace bio.nu/forum with filmsnack.se and redirect to that new location
Anyone?
kabatak
December 19th, 2004, 16:20
not sure if i understood it correctly. will the old forum still be up and you just want to redirect them to the new domain? if so, you can put this in the header file (or any file which is included in all forum pages)
$old_url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$new_url = str_replace('bio.nu/forum', 'filmsnack.se', $old_url);
header('location: '.$new_url);
Peo
December 20th, 2004, 06:00
Thanks, it almost works now. It redirects to http://www.bio.nu/forum/www.filmsnack.se/index.php?
notice the www.filmsnack.se part has just been added to the old location.
So, how do I fix that?
HugoLeite
December 20th, 2004, 06:31
Try something like
header( 'location: www.fimsnack.se' . $_SERVER['REQUEST_URI']);
i think it should work that way
kabatak
December 20th, 2004, 06:53
yeah I think Hugoleite's is simplier, just add http://
header( 'location: http://www.fimsnack.se' . $_SERVER['REQUEST_URI']);
Peo
December 20th, 2004, 08:08
Thanks, but if I add http:// like this i get an error:
<?php header( 'location: http://www.filmsnack.se' . $_SERVER['REQUEST_URI']); ?>
If I just add www.filmsnack.se it gets redirected to http://www.bio.nu/forum/www.filmsnack.se/forum/index.php
HugoLeite
December 20th, 2004, 08:15
Hmmm thats odd... could you please post the error you are getting ?
[ --- Edit --- ]
Or try something like this
$goThere = "http://www.filmsnack.se{$_SERVER['REQUEST_URI']}";
header( "location: {$goThere}" );
Peo
December 20th, 2004, 08:34
I get a 404 and it stays at http://www.bio.nu/forum/index.php?
Also the new one you posted HugoLeite returns the same 404 message.
HugoLeite
December 20th, 2004, 08:40
header( "http://www.filmsnack.se/index.php?{$_SERVER['QUERY_STRING']}" );
I got it, in www.filmsnack.se you don't have the '/forum/' thats the reason for the 404, so this one should work since it only adds the URL parameters that come after the '?' mark.
Peo
December 20th, 2004, 10:10
Thanks guys, it's working now! See here: http://www.bio.nu/forum/index.php?showtopic=1315&view=findpost&p=47153
And this is the exact code I ended up using:
<?php header( 'location: http://www.filmsnack.se/index.php?' . $_SERVER['QUERY_STRING']); ?>
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.