Saturday, November 10, 2007
« php 301 redirect | Main | 30 Years of Information and Educational ... »

Place the following code into the header of any asp 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 ( strcomp( lcase( Request.ServerVariables("SERVER_NAME") ) , "www.sitename.com", 1 ) <> 0 _
AND Request.ServerVariables("SERVER_PORT") = 80 _
AND strcomp( lcase( Request.ServerVariables("REQUEST_METHOD") ) , "get" , 1 ) = 0 _
) then
URL = "http://www.sitename.com" & Request.ServerVariables("SCRIPT_NAME")
if len ( request.servervariables("QUERY_STRING" ) ) > 0 then
URL = URL + "?" + request.servervariables("QUERY_STRING" )
end if
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", URL
Response.End
end if
%>

Saturday, November 10, 2007 8:06:33 AM (Pacific Standard Time, UTC-08:00)    Disclaimer  |   |  Related posts:
How do you Upgrade Planet Earth by Marcus Ranum
How do I use and find and create Twitter Lists
Navajo Code Talker Willard V. Oliver passes on
Sequoia Voting Machine source code, free to download and study, no NDAs
Subscribe to the feed version of Educational CyberPlayGround
The Conscience Un-Conference: Using Social Media For Good is free