View Full Version : Prevent Url Variables that arent in use

01-06-2008, 05:37 AM

Does anyone know how to prevent people from putting unused variables in a page. For example if you go to http://google.com/?a=a it gives a 404 error. I'd like to do the same or do a 301 redirect.


01-07-2008, 12:09 AM
Here's a bit of PHP I use. It redirects ALL query strings to the equivalent URL without the query string though, so if you want to allow some, you'll need to tinker with it. Perhaps by having an array of "safe" values that can be used. Should be a good start point though.

$requested = $_SERVER['REQUEST_URI'];
if (strpos($requested, '?') > 0){
$uri_array = explode('?', $requested);
$redirect = 'http://www.yourdomain.com'.$uri_array[0];
header("HTTP/1.0 301 Moved Permanently");
header("Location: $redirect");