11

My website will be down for maintenance for some time, and I want to make sure sure that (1) search engines see a HTTP 503 error code for every page, and (2) humans see a friendly message describing the downtime, in line with downtime SEO best practices.

How do I set up IIS 7.5 such that every request gets a custom 503 error message?

3 Answers 3

13

One way is to use the Url-Rewrite extension.

You can then use a rule like this to catch all requests:

<system.webServer>
    ...
    <rewrite>
        <rules>
            <rule name="SiteDown" stopProcessing="true">
                <match url=".*" />
                <action type="CustomResponse" statusCode="503" statusReason="Down for maintenance" statusDescription="will be back up soon" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

This takes care of the Search Engines, for the users you can add the following:

<system.webServer>
      ...
     <httpErrors existingResponse="Auto" errorMode="Custom" defaultResponseMode="File">
        <remove statusCode="503" subStatusCode="-1" />
        <error statusCode="503" path="503.html" />
     </httpErrors>
</system.webServer>

and then put a 503.html file in the root of your site which has a nice error message. Because you can not use styles or images in the page that are on the site itself, you need to link to another site or put all styles and images inline in the html page.

3
  • I am getting 500 internal server error instead of 503
    – Jeeva Jsb
    Feb 5, 2016 at 10:38
  • This works but it means whenever we down our website for maintenance or stop our app pool then we have to add these configurations in our web.config file & later need to remove these once app is up. This is what I understand...please correct me if I am wrong. Jul 3, 2018 at 12:26
  • @AnkushJain - correct, but you can script them so you don't have to manually change the configs. Jul 3, 2018 at 12:30
9

If one's using a .NET application with IIS, one can also use an app_offline.htm file to shut down an application and prevent pages from being requested with an appropriate 503 error code.

2
  • 2
    +1, but for ASP.NET 2.0 apps status code returned is 404 ! Solution is temporary set 4.0 app pool to the site Mar 16, 2013 at 13:33
  • this is the best answer, simple, catch all page, rules proper code!
    – Zyo
    Jul 7, 2016 at 4:33
3

You can setup a web.config in the following and put it in your root directory.

<rule name="Send 503" patternSyntax="Wildcard" stopProcessing="true">
  <match url="*" />
  <action type="CustomResponse" statusCode="503" subStatusCode="0" statusReason="Service Unavailable" statusDescription="The server is down for maintenance" />
</rule>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .