Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
301 redirect

Posted by John_Moylan (jfp), 24 July 2005
I have created this as a 404 (not found) error page to do a 301 (Moved Permanently) redirect.

Code:
<?php

$new_domain = 'http://www.newdomain.co.uk';
$request_uri = $_SERVER['REQUEST_URI'];

$new_location = $new_domain . $request_uri;

header('HTTP/1.1 301 Moved Permanently');
header("Location: $new_location");
?>


Seems to work and it is very simple I know, but is it too simple?
Have I missed anything that anyone can see/think of?

I did this as a php 404 page instead of using mod_rewrite for any future "enhancements/hoop jumping" that *may* be needed that could not be done with mod_rewite.

Input please.

Thanks
jfp

edit: All I'm doing is moving a site from .co.uk to .com varient of a domain name. I know the code says the opposite, but I'm only testing.

Posted by admin (Graham Ellis), 24 July 2005
PHP is written to make this things appear easy  

If I was doing this, I would do sanity checks with relative and absolute paths within the pages to make sure that all of them were correctly diverted (and that the new domain didn't have any old absolute URLs in it to the old domain).  Would also check that it worked with data content on POST and GET methods ... it probably does.

I suspect that you'll loose cookies??

Posted by John_Moylan (jfp), 28 July 2005
Thanks Graham.

I don't think losing cookie data is an issue in this case, thankfully.

Thanks again for your input on this.

john



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho