Saturday, November 10, 2007
« Dan Cassidy How The Irish Invented Slang... | Main | ASP 301 redirect »

Place the following code into the header of any php document and it will redirect the page access to the correct site name. while preserving the script name and the query arguments.



// If the server name is not www.sitename.com we can do the redirect to www.sitename.com.
// The only time we can is if the method is a GET
// (no way to pass along the POST arguments) and its on port 80 (don't want to redirect the SSL).

if ( strcmp( strtolower( $_SERVER['HTTP_HOST'] ) , "www.sitename.com" ) != 0 &&
strcmp( strtolower( $_SERVER['REQUEST_METHOD'] ) , "get" ) == 0 &&
$_SERVER['SERVER_PORT'] == 80 )
{
header("Location: http://www.sitename.com" . $_SERVER['REQUEST_URI'] );
header("HTTP/1.0 301 Moved Permanently");
exit ;
}

Saturday, November 10, 2007 4:00:04 PM (GMT Standard Time, UTC+00:00)    Disclaimer  |  Comments [0]  |  Related posts:
Top Tech Trends for ALA (Summer ‘08)
SITESEEING: no key keyboard
Senator Dodd Speaks in Opposition to FISA Bill on Floor of U.S. Senate
Library of Congress Update
Educational CyberPlayGround given Hot Site Awards
VIDEO: Howard County Libraries to go all Open Source this year