64

For my IIS website, I'd like to redirect ALL requests to ONE page. The purpose of this is that I want to do some maintenance on the database (take it off-line) that all my web applications use. I have about 50 web apps running under this website, so I'd like to avoid visiting each of them to change something. I'm thinking I could make a single change in machine.config? Any hints would be appreciated.

5 Answers 5

100

If you are using ASP.NET 2.0 (or higher), you can drop an app_offline.htm page on the root.

More info here.

9
  • That's cool, I didn't know that. Although our sites at work are a mix of aspx and htm pages so it wouldn't work for us.
    – pipTheGeek
    Commented Nov 18, 2008 at 22:48
  • Nice, I wasn't aware of this either. Commented Nov 18, 2008 at 22:49
  • I found out about app_offline.htm reading Scott Gu's blog, but am surprised I haven't read about it elsewhere. It works as advertised, which helps. Commented Nov 18, 2008 at 22:57
  • +1 Note: this returns a 503 response, which is exactly what you want in most cases (and in the OP case)
    – Myster
    Commented Apr 10, 2012 at 4:57
  • 1
    Hmm.... I'm getting 404 for all pages when I use this solution. not 503. In this particular case that's okay but usually that would not be okay.
    – BVernon
    Commented Jun 10, 2016 at 19:07
57

in webconfig

 <rewrite>
        <rules>
            <rule name="redirect all requests" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                </conditions>
                <action type="Rewrite" url="index.php" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
6
  • 6
    Giving a +1 because it's an alternative solution (that happened to work for me), however it should be pointed out that a rewrite is not the same as a redirect so if a real redirect is required then this will not work.
    – Davy8
    Commented Jan 24, 2011 at 19:50
  • 3
    If you need a redirection, you will only have to change the action type to Redirect. Commented Nov 18, 2014 at 13:29
  • 5
    This rewrite rule will only redirect requests to folders, not files. The OP wanted to redirect all requests. To do that, remove the <conditions> tag.
    – Keith
    Commented Jun 8, 2015 at 15:21
  • for redirect <action type="Redirect" url="index.html" appendQueryString="true" redirectType="Permanent" />
    – Shahdat
    Commented Jul 20, 2016 at 19:13
  • 1
    What's beautiful is that this still works on IIS 10 on Windows Server 2016! Commented Jan 21, 2019 at 21:30
11

Make all the pages un-available, probably stop the current web site and create an entire new completly blank site in its place. Then put up a custom error page for the 404 (file ot found) error. Custom Errors is a tab on the properties dialog of the web site in IIS. Just create the page you want to send, then change the entry for 404 on the custom errors tab to point to the new file you just created.

2
  • This was an excellent suggestion, and worked for my large mix .NET/classic ASP applications. Very easy to implement.
    – Mike
    Commented Sep 23, 2012 at 17:15
  • 2
    There is a big problem with this, although aesthetically the UI will work, if you happen to have a Search Engine crawling your site, it will all of a sudden receive a bunch of 404's and remove the content from the search results.
    – Talon
    Commented May 15, 2015 at 10:13
3

In IIS 10 there is an optional component "HTTP Redirect" (it may be available in earlier IIS versions; I don't know). It allows you to set up very simple catch-all redirects, using any of the common HTTP redirect response codes. This can be installed via Server Manager, in Windows Server 2019.

1

Could you create a new site in IIS with a binding to port 80 with a blank host-header (much like the Default site) and then stop the other site(s)? That way all requests would be handled by the new site, which could simply be a static HTML page notifying users that the site is down for maintenance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.