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
If you are using ASP.NET 2.0 (or higher), you can drop an app_offline.htm page on the root.
-
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. Commented Nov 18, 2008 at 22:48
-
-
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)– MysterCommented Apr 10, 2012 at 4:57
-
1Hmm.... 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.– BVernonCommented Jun 10, 2016 at 19:07
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>
-
6Giving 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.– Davy8Commented Jan 24, 2011 at 19:50
-
3If you need a redirection, you will only have to change the
action type
toRedirect
. Commented Nov 18, 2014 at 13:29 -
5This rewrite rule will only redirect requests to folders, not files. The OP wanted to redirect all requests. To do that, remove the
<conditions>
tag.– KeithCommented Jun 8, 2015 at 15:21 -
for redirect <action type="Redirect" url="index.html" appendQueryString="true" redirectType="Permanent" />– ShahdatCommented Jul 20, 2016 at 19:13
-
1What's beautiful is that this still works on IIS 10 on Windows Server 2016! Commented Jan 21, 2019 at 21:30
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.
-
This was an excellent suggestion, and worked for my large mix .NET/classic ASP applications. Very easy to implement.– MikeCommented Sep 23, 2012 at 17:15
-
2There 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.– TalonCommented May 15, 2015 at 10:13
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.
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.