Forum Moderators: coopster

Message Too Old, No Replies

REQUEST_URI issue

Redirecting using a 404 page to a new site..

         

donovanh

11:31 am on Jun 24, 2004 (gmt 0)

10+ Year Member



Hi,

I'm hoping this will be an easy one.. I'm trying to use a custom 404 to redirect pages from my old url to a new url. The code i'm using is like this:


$redir = $_SERVER["REQUEST_URI"];
header("Location: [domain.com$redir");...]

However this is not working, for some reason the $redir is going through as "404.php", rather than the trailing part of the address. Any suggestions on what I'm doing wrong?

Many thanks,

Don

coopster

5:27 pm on Jun 24, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Not really. Have you tried halting the script and printing out the link to see if the link itself is your issue?
$redir = $_SERVER["REQUEST_URI"]; 
exit("Location: http://www.domain.com$redir");
header("Location: http://www.domain.com$redir");

donovanh

7:56 am on Jun 25, 2004 (gmt 0)

10+ Year Member



Thanks for the reply. I have tried halting the script, and $redir is always '/404.php'.

Don

donovanh

9:40 pm on Jun 25, 2004 (gmt 0)

10+ Year Member



I've been looking into this and I think I need to implement a redirect using .htaccess. I was going to use this:
redirect 301 / http:// www.newsite.com/

But this will send all the links to the root of the new site address. Is there a .htaccess way to send all pages to the equivalent location at the new domain? For example:

http:// www.foo.com/section/2/ -to-> http:// www.bar.com/section/2/

TIA,

Don

jdMorgan

9:50 pm on Jun 25, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> But this will send all the links to the root of the new site address.

No, it will send any request that starts with "/" to the new server, and append anything that follows the slash to the new URL.

See Redirect and RedirectMatch in Apache mod_alias [httpd.apache.org].

The only problem with this method is that if your use a canonical url instead of a local url-path, the 404 status code will be lost, and be replaced with a 302-Found status, as described in the documentation.

Jim

donovanh

10:26 pm on Jun 25, 2004 (gmt 0)

10+ Year Member



Nice. Thanks jdMorgan. I had misunderstood how the redirect functioned.

Don