I want to display an "under maintenance" html page when my site is stopped in iis automatically instead of manually adding the app_offline.htm everytime . Is it possible to route the url to the maintenance page automatically whenever the site is stopped? From what i understand when the site is stopped nothing is getting hit,So is there a way to reroute the path instead of keeping a proxy server? Right now i am getting a "This site can’t be reached. xx.x.x.x refused to connect."
If you stop a Web site, means the Web site no longer listens for requests on all of its bindings. This prevents any subsequent requests from being received by your applications in the Web site; new connections to your Web site will fail as if it didn't exist.
So first start your site and create a temporary page that is used to redirect all the pages.
Below is URL rewrite rule which redirects all the pages to the under-construction page:
<rule name="RequestBlockingRule1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{URL}" pattern=".*" />
<add input="{REQUEST_URI}" pattern="temp.html" negate="true" />
</conditions>
<action type="Redirect" url="temp.html" />
</rule>
Related
A Temporary down page (e.g. updating your servers SW) should ideally have a response code of 503, but you could get away with 307, but in no case should it be 200 (as google will index this and it will affect your SEO)
In IIS rewrite rules, you have 3 options for implementing a redirect to a down page, rewrite, redirect and customResponse:
<action type="Rewrite" url="/site1.html" />
<action type="Redirect" url="/site1.html" redirectType="Temporary" />
<action type="CustomResponse" statusCode="503" subStatusCode="0" statusReason="Site Unavailable" statusDescription="Down for maintenance" />
The problem is if you want a 503 response, you cant redirect to the required page.
We have 3 websites for different brands using episerver CMS.
When we do maintenance, or just want to take a site down, we have a single azure web app (aka iis) which has 3 holding pages, one for each.
so our site down website has 3 pages:
/site1.html
/site2.html
/site3.html
We use Azure traffic manager to point to the live site or the site down page, and we currently have redirects which work, but incorrectly give 200 response:
<rewrite>
<rules>
<rule name="site1" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="mysite" />
</conditions>
<action type="Rewrite" url="/site1.html" />
</rule>
<rule name="site2" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="myothersite" />
</conditions>
<action type="Rewrite" url="/site2.html" />
</rule>
etc.
</rules>
</rewrite>
In order to fix this issue (offer a different site down page per site, and respond with 503), what are the options?
I would guess its possible to setup something like 3 different named virtual hosts, each with nothing except a custom 503 error page + a catch all CustomResponse action? Any examples of such a config?
To be clear, our app may well be running normally, but we may want to use our traffic manager to point the public at a "down" page which has a 503 respose during maintenance. The website sorving the down page has nothing to do with the website serving the site/applicaion itself.
Sadly, as the Microsoft document describes – there is no way to customize the 503 HTTP error.
Even use rewrite to make it display custom 503 page, In fact the request get into IIS and rewrite successful, then response to client. The whole process is perfect and your web service doesn’t stop.
The error is detected by the IIS server as it attempts to hand the incoming request to application. Everything application does is performed in its app pool. Modules like rewrite and custom error page are all executed in this way. 503 handled by the http.sys you cannot create a custom error page at all, as it is processed before it gets to iis. Therefore, both hope that the web server will stop reporting 503, but also hope that the server can process the request to display the page you defined. These two conflicts.
If your application is asp.net, there’s another way to custom 503. You can place a text file named "app_offline.htm" in the root of the site, all requests to that website will redirect to that app_offline.htm file. Basically, if you need to take an entire ASP.NET site offline, you can place some nice message in that file. Then, any new requests to a URL, any URL, in that website will redirect to that file allowing you to do maintenance to the site, upgrades, or whatever. It is not really a redirect though. ASP.NET essentially shuts down the site, unloads it from the server, and stops processing any requests to that site. That is, until you delete the app_offline.htm file - then things will continue as normal and your ASP.NET site will load up and start serving requests again.
Azure App Service AlwaysOn works perfectly once there is no custom domain set for the web application. Once custom domain is added along with URL rewrite rule to redirect all incoming request to it, application starts to response slowly after some time of inactivity. Logs show that AlwaysOn still pings azure domain and gets HTTP 301 response ans is not trying to request new URL.
Log without custom domain:
2017-06-20 17:17:02 ZZTESTSITE GET / X-ARR-LOG-ID=743965b6-d3e2-42b9-9353-7772f9fbc898 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 200 0 0 11433 652 15
Log with custom domain
2017-06-21 13:28:52 ZZTESTSITE GET / X-ARR-LOG-ID=ffcd5992-5019-48ca-a386-76443a8c7226 80 - ::1 AlwaysOn ARRAffinity=b5289afa9cd711b67c1fe9137a6e3ff232f80bd3fa1bd96e9fc89992472b4e57 - zztestsite.azurewebsites.net 301 0 0 553 652 46
URL Rewrite rule:
<rule name="Redirect requests from default azure websites domain to custom one" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://mycustomdomain.com" redirectType="Permanent" appendQueryString="false"/>
</rule>
Additionally once SSL in enabled and another rule is added to redirect all requests to HTTPS, same issue will arise.
How can I tackle this problem? I found two possible directions:
Push AlwaysOn to ping custom domain (possibly https as an option)
Change URL Rewrite rule to one allowing AlwaysOn to ping azure domain, but all other shall be redirected
Please advise.
Try adding this line to your conditions:
<conditions>
<add input="{HTTP_HOST}" pattern="^zztestsite\.azurewebsites\.net$" />
<add input="{WARMUP_REQUEST}" pattern="1" negate="true" />
</conditions>
This tells is not to redirect for the Always On pings. Also note that I removed the MatchAny, as you really want MatchAll here (irrelevant when you only had one).
See here for a more complete example. It's for redirecting http to https, but the core idea is the same with respect to Always On requests. That example is an xdt transform, so it looks a bit different from 'straight' config. In fact you might consider using such xdt instead of polluting your web.config.
Finally I found the rule which works
<rule name="AlwaysOn agent requests without any redirections" stopProcessing="true">
<match url="^$"/>
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="^AlwaysOn$" />
</conditions>
<action type="None" />
</rule>
I put it as a first rule. Then other rules follow like "azure domain to custom domain redirect" and "HTTP to HTTPS".
David's answer was helpful however solves a bit different issue.
I'm trying to use the URL Rewrite module for IIS 7.5 to redirect all HTTP requests to HTTPS for my ASP.NET website. The site works fine at the moment but forces the user to type the https:// in the address bar.
I followed the instructions in this article. Everything seems to be fine: I've tried putting the rule in the web.config and it shows up in the UI as it should; I've also done the reverse and can see the changes in the web.config when I use the UI to add the rule. I have RequireSSL unchecked for the site. Unfortunately I still just get a 404 when I try to hit the site via http://.
I've tried a few different action urls including {HTTP_HOST}/{R:1} and the one shown below.. nothing works.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
</system.webServer>
I'm fairly new to this and pretty frustrated at this point. Seems like this should be a lot easier. Any advice would be appreciated, thanks..
Reposting from ServerFault as it's been sitting unanswered for a while.
HTTP Error 404. The requested resource is not found
Do you actually have binding for HTTP 80 port? Sounds like you do not have it (only HTTPS).
The reason I'm asking is the quoted text is the exact message that I would see if I request unknown to IIS domain (when there is no catch-all defined) or domain is not bound to the requested port.
I want to ensure that anybody who goes to http://example.com/* gets automatically redirected to http://www.example.com/*. Currently, IIS allows either URL form to work, meaning that any page can be accessed at multiple URLs, which has a number of disadvantages (SEO, etc).
Is there any way to do this built into IIS (especially IIS 6) without setting up a third-party rewriting engine like this? It seems like a bazooka to kill a mosquito.
The easy way would be to simply remove the DNS entries for 'www.mysite.com', so the only DNS entries that exist are for 'mysite.com'.
Alternatively, here's a couple of techiques for redirecting to a canonical URI:
http://www.kalyani.com/2010/01/redirecting-to-canonical-url-in-iis7/
https://web.archive.org/web/20211020203216/https://www.4guysfromrolla.com/articles/072810-1.aspx
http://www.stevenhargrove.com/redirect-web-pages/
Basically you want to hand back a 301 Moved Permanently status for the non-canonical URIs, along with the canonical URI so the user agent may load it instead.
I have another solution for you:
<rule name="Canonical domain name" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" negate="true" pattern="^www\.([.a-zA-Z0-9]+)$" />
</conditions>
<action type="Redirect" url="http://www.{HTTP_HOST}/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
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.
If you are using ASP.NET 2.0 (or higher), you can drop an app_offline.htm page on the root.
More info here.
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>
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.
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.