note 92110 added to function.header

From: Date: Thu, 09 Jul 2009 09:43:37 +0000
Subject: note 92110 added to function.header
Groups: php.notes 
Request: Send a blank email to php-notes+get-158095@lists.php.net to get a copy of this message
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. ---- Server IP: 92.48.74.199 Probable Submitter: 213.162.121.75 ---- Manual Page -- http://www.php.net/manual/en/function.header.php Edit -- https://master.php.net/note/edit/92110 Del: integrated -- https://master.php.net/note/delete/92110/integrated Del: useless -- https://master.php.net/note/delete/92110/useless Del: bad code -- https://master.php.net/note/delete/92110/bad+code Del: spam -- https://master.php.net/note/delete/92110/spam Del: non-english -- https://master.php.net/note/delete/92110/non-english Del: in docs -- https://master.php.net/note/delete/92110/in+docs Del: other reasons-- https://master.php.net/note/delete/92110 Reject -- https://master.php.net/note/reject/92110 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158095) next »