Skip to content

Instantly share code, notes, and snippets.

@halgatewood
Created June 2, 2014 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halgatewood/aa3c22925452271c8c3f to your computer and use it in GitHub Desktop.
Save halgatewood/aa3c22925452271c8c3f to your computer and use it in GitHub Desktop.
If the first parameter is not found then redirect to the second, If it is then do nothing.
function redirect_if_not_found( $item, $to )
{
if(!$item)
{
// WHATEVER OTHER HEADER OPTIONS YOU WANT CAN GO HERE, LIKE A 301
header("HTTP/1.1 301 Moved Permanently");
// REDIRECT
header("Location: $to");
}
}
// USAGE
redirect_if_not_found( $location, "/locations" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment