wemustdesign Posted December 17, 2010 Share Posted December 17, 2010 I am using the code below for my webpage. When no or non existant querystring is passed the user is directed to the homepage. I want to change this so that if a user goes uses an invalid query string (?page=oldcontent) they are directed to a 'not found page'. Can this be done with the way I hae set this up? switch ($page) { case 'about': include 'about.php'; break; case 'contact': include 'contact.php'; break; default: include 'homepage.php'; } Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/ Share on other sites More sharing options...
Rifts Posted December 17, 2010 Share Posted December 17, 2010 http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=custom+404 Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148827 Share on other sites More sharing options...
Maq Posted December 17, 2010 Share Posted December 17, 2010 You should be doing this through your web server (most likely Apache). Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148828 Share on other sites More sharing options...
desjardins2010 Posted December 17, 2010 Share Posted December 17, 2010 if i understand correctly you simply want to send them to a certain page if their query is not found? Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148830 Share on other sites More sharing options...
BlueSkyIS Posted December 17, 2010 Share Posted December 17, 2010 this is what i do: if ($invalid_request) { header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); header("Status: 404 Not Found"); header("location: 404.html"); exit; } where 404.html is the page you want to send the user to... Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148833 Share on other sites More sharing options...
wemustdesign Posted December 17, 2010 Author Share Posted December 17, 2010 But non of this would work with a switch statement though? If the page is not found it goes to the default 'homepage.php' in the switch statement. Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148837 Share on other sites More sharing options...
BlueSkyIS Posted December 18, 2010 Share Posted December 18, 2010 make homepage case '' (no page), then default to switch ($page) { case 'about': include 'about.php'; break; case 'contact': include 'contact.php'; break; case '': include 'homepage.php'; break; default: header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); header("Status: 404 Not Found"); header("location: 404.html"); exit; } Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148838 Share on other sites More sharing options...
wemustdesign Posted December 18, 2010 Author Share Posted December 18, 2010 That worked a treat, thanks for taking the time! Quote Link to comment https://forums.phpfreaks.com/topic/222022-creating-a-page-not-found/#findComment-1148840 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.