HEX
Server: Microsoft-IIS/10.0
System: Windows NT ITPWINWEBSVR22 10.0 build 20348 (Windows Server 2022) AMD64
User: www.conferencesearch.co.uk (0)
PHP: 8.3.30
Disabled: NONE
Upload Files
File: D:/web/non.www.redirect/404.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 on 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
LSite = Request.ServerVariables("HTTP_HOST")
LIsSecureSite = LCase(LSite) = "secure.itpartnership.com"
' 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
  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
  
  ' (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

Else
  '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
%>