PHP get: request query string to redirect


Sometimes you need to redirect your visitors to another page according to information they have entered in a form, or, if you changed an address in your site, you may need to detect a string in the old address and then redirect your visitors to the new address.

This code detects a value called “whatever” and redirects accordingly:

<?php if (array_key_exists('whatever', $_GET)) {
 if ($_GET['whatever'] === '1') {
 header('Location: https://www.thefreewindows.com');
 }
 else if ($_GET['whatever'] === '2') {
 header('Location: https://www.thefreewindows.com/freeware-categories/');
 }
}
?>

And, if you want a permanent redirect add the following line:

header( "HTTP/1.1 301 Moved Permanently" );