note 92110 deleted from function.header by danbrown

From: Date: Thu, 09 Jul 2009 14:42:02 +0000
Subject: note 92110 deleted from function.header by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158113@lists.php.net to get a copy of this message
Note Submitter: BallooTheBear ---- Hi, As a numpty beginner I thought I would add some code I put together to help file/site redirection. Changing domains is a pretty stressful time, and I hope the following will help someone. I've tested it on my server, and checked it with the online redirect checkers, and it seems to work fine. I'm very sure there are much better ways to code, but........ There are many easy ways to alter this code to what you want, have fun. If you spot any holes, I'm sure you will comment! <?php // put this file in your www root directory, put a 404 redirect to this file (I call it moved.php) in the HTTP.conf or virtual server file/.htacces, then alter entries, done!! ob_start(); $filename = NULL; $n ="http://www.xybrassband.com/"; // new (or same) Domain $moved_file_names=array(); $moved_file_names['Beginners.htm'] = "beginners.php"; $moved_file_names['Links.htm'] = "links.php"; $moved_file_names['The MD.htm'] = "themd.php"; $moved_file_names['news.htm'] = "news.php"; $moved_file_names['Diary.htm'] = "diary.php"; $moved_file_names['Band photos'] = "photos"; $moved_file_names['Links.htm'] = "links.php"; $moved_file_names['tinc'] = "index.php"; $moved_file_names['Band photos/a folder with spaces/Diary.htm'] = "diary.php"; $moved_file_names['Band photos/Another_folder/Contacts.htm'] = "contacts.php"; $filename=ltrim(html_entity_decode($_SERVER['REDIRECT_URL']),"/"); if(isset($moved_file_names[$filename])) { error_log("Redirected [".$filename."] - [".$moved_file_names[$filename]."]",0); header("Status: 301"); # 301 Moved Permanently, or whatever you want header("Location: ".$n.$moved_file_names[$filename]); } else { error_log("Unknown file in redirect!",0); // then look in access/error the log header("HTTP/1.0 404 Not Found"); # not 301 Moved Permanently // or you could point them to your index file? } exit(); ?> Oh, and thanks to the other comments, from which I drew some of this code.

« previous php.notes (#158113) next »