File: D:/web/non.www.redirect/404 - (m. redirect attempt - abandoned).asp
<%Option Explicit%>
<%Response.Buffer = True%>
<%
' (SS,6/8/10) permanent redirection of sites without "www." prefix to site prefixed with "www."
' if site already has "www." prefix then show the normal bad request error 400
' for this custom error handling routine to work add "/404.asp" as URL to custom errors tab of default web site
' also add 404.asp to the documents tab as a default
' make sure there are no host header values in the advanced section of web site tab
' also disable session cookies by unticking "Enable session state" in Configuration / Options
' (SS,18/7/12) Status changed to "404 Not Found", also had to add index.asp to do Response.Status = "404 Not Found"
' otherwise directory browsing not allowed message will appear.
' (SS,26/7/12) Issue discovered in Google Chrome when renaming www.hyperflight.co.uk to remove www.,
' or entering hyperflight.co.uk on iPad, appearing fine in Firefox and IE.
' it would redirect to www.hyperflight.co.uk/index.asp and show page not found error.
' To solve this I removed index.asp which caused error "403 directory browsing not allowed".
' I also changed the error handler for 403 to go to 404.asp.
' Also removed <h1>Not Found</h1> from HTML below just before <h2>
' (SS,22/6/13) added redirect for http://secure.itpartnership.com to https://secure.itpartnership.com
' previously it was going to http://www.secure.itpartnership.com which doesn't exist
Dim LSite, LQuery, LIsSecureSite, LRedirectPrefix, LDoRedirect
LSite = Request.ServerVariables("HTTP_HOST")
LIsSecureSite = LCase(LSite) = "secure.itpartnership.com"
' (SS,1/3/15) following moved here from inside first "if"
LQuery = Request.ServerVariables("QUERY_STRING")
If LQuery <> "" Then
Dim LPos
' format of query string is 404;http://ontheworldweb.com:80/web_site_design.htm
LPos = InStr(LQuery, ":80/")
If LPos > 0 Then
LQuery = Mid(LQuery, LPos + 4, Len(LQuery))
End If
End If
' if site doesn't start with "www." then do the redirect else show the Bad Request content
If LCase(Left(LSite, 4)) <> "www." Or LIsSecureSite Then
LDoRedirect = True ' (SS,1/3/15)
' (SS,1/3/15) if prefix is "m." i.e. for mobile sites then we'll be redirecting to www. (i.e. CIRC site which is responsive design)
' so m. in site name is removed
If LCase(Left(LSite, 2)) = "m." Then
LSite = Mid(LSite, 3)
End If
Else
LDoRedirect = False
'Response.Status = "400 Bad Request"
' (SS,18/7/12) status now changed to "404 Not Found"
Response.Status = "404 Not Found"
%>
<html>
<head></head>
<body>
<font color="blue">
<h2>Site <font color="darkblue"><%=(Request.ServerVariables("HTTP_HOST"))%></font> is stopped or doesn't exist</h2>
</font>
</body>
</html>
<%
End If
' (SS,1/3/15) moved here from above
If LDoRedirect Then
' (SS,22/6/13) redirect to https for secure.itpartnership.com, else prefixed by www (as before)
If LIsSecureSite Then
LRedirectPrefix = "https://"
Else
LRedirectPrefix = "http://www."
End If
' Permanent redirection
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", LRedirectPrefix + LSite + "/" + LQuery
Response.End
End If
%>