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
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho