Search code examples
http-redirectasp-classicwildcardstatus

HTTP status 410 entire domain using classic ASP


Two domains are pointing at my IIS 7.5 server. One domain serves a site, the other I would like to return a 410 Gone status for ANY URL that references that domain. Because I have not added a DNS entry for the 410 domain, the server returns the IIS default site. I added the following to the default.asp file on the default site:

<%
if instr(lcase(Request.ServerVariables("SERVER_NAME")),"legacy.somedomain.com") then
    response.Status="410 Gone"
    response.Write(response.Status)
    response.End
end if
%>

This works correctly is someone visits http://legacy.somedomain.com however it fails if someone visits http://legacy.somedomain.com/somepage/, a sub page URL: of the domain. I thought the above script would have wildcarded the request. Can it be modified to catch the domain and all sub page occurrences?

At present, if a user visits legacy.somedomain.com/somepage/ the system 404 page is displayed.


Solution

  • Create a Global.asa file in the web directory with the following code

    <script language="vbscript" runat="server">
    
    sub Session_OnStart
        Session("started")=now()
    end sub
    
    sub Session_OnStart
        if instr(lcase(Request.ServerVariables("SERVER_NAME")),"legacy.somedomain.com") then
            response.Status="410 Gone"
            response.Write(response.Status)
            response.End
        end if    
    end sub
    
    </script>
    

    However you might actually be better of doing a permanent redirect rather than a Gone.