I need to do a 410 Gone on a bunch of html pages for a site running on IIS. Is there a simple way to do them all at once, like an htaccess file, or do I have to do it one at a time in IIS?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I do it this way:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if( listOf410urls.Contains(Request.RawUrl) )
{
Response.StatusCode = 410; Response.End();
}
}
And then I have in webconfig system.webServer
<httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL">
<remove statusCode="410" subStatusCode="-1" />
<error statusCode="410" path="/Error410.aspx" responseMode="ExecuteURL" />
</httpErrors>
This means that all the pages that return 410 will be fetched to the user & search engines using /Error410.aspx
page.
In Error410.aspx I also set Response.StatusCode = 410;
otherwise the statuscode will be 200 OK.