how to create multiple custom 503 pages in IIS - iis

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.

Related

Add custom HTML page when iis site is stopped

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>

web.config redirect to another domain on 404 error

We are migrating our old site to a new one (wordpress hosted on Azure) but for some reasons we need to maintain the old one one online. Suppose the site are:
new site www.site.com
old site www.oldsite.com
This is what we need:
if a user enter www.site.com/somepath and this doesn't exist, it must be redirected to www.oldsite.com/somepath.
Is it possible by setting url rewrites in web.config or by redirecting 404 error to the old domain?
Thank you in advance,
Marco
From your information, I'd assume you are using WordPress template (not WordPress on Linux) from Azure Marketplace (in which during the WordPress web provisioning, you are asked to chose whether Azure MySQL or MySQL in App option). You can download IIS Manager extension and remotely connect to your site then start writing your rule. You can also download the web.config file (via FTP and make it up yourself). Here is the reference of web.config https://social.technet.microsoft.com/wiki/contents/articles/32229.azure-create-an-url-rewrite-azure-web-app.aspx
The below is sample rule
<rewrite>
<outboundRules>
<rule name="404redirection">
<match filterByTags="None" serverVariable="{RESPONSE_STATUS}" pattern="^404" />
<conditions>
<add input="{HTTP_HOST}" type="Pattern" pattern="^http://newwebsite.net/somepath(.*)">
</conditions>
<action type="Redirect" value="http://oldwebsite.net/somepath(.*)" />
</rule>
</outboundRules>
</rewrite>
Note that this is the sample rule based on the web server variable with HTTP response (404). If you WordPress uses some custom query strings or so on, the rule is supposed to be more complicated than this one.

Redirect to FQDN in IIS Not Working

None of the answers I've found to questions like this (notably this one) work for me, so here I go.
We are running IIS 8 on Windows Server 2012 R2. We have a wildcard certificate (*.mydomain.com) installed on the server. On the Default Web Site we have a single binding to accept incoming https requests on port 443. I have a second Web Site set with a single binding to accept incoming http requests on port 80.
On the latter Web Site I've created a URL Rewrite rule to redirect all incoming non-HTTP traffic to https://myserver.mydomain.com{REQUEST_URI}, and this works perfectly. If I browse to either http://myserver.mydomain.com/homepage or http://myserver/homepage, I am sucessfully redirected to the HTTPS version of the site with the full domain name included and thus it loads just fine.
If I browse to https://myserver.mydomain.com/homepage, the site also loads perfectly.
However, I am trying to create another URL Rewrite rule on the Default Web Site so that requests to https://myserver/homepage (Note: HTTPS but the full domain name is omitted) are redirected to the https://myserver.mydomain.com/homepage. The reason for this is that the SSL certificate is only matched if the full domain is included. As it stands, if I enter https://myserver/homepage I get a security warning (NET::ERR_CERT_COMMON_NAME_INVALID).
I've created the rule which I think should work, based on the answer I linked to above, but it doesn't work and I don't know why. My rule look like this:
<rewrite>
<rules>
<rule name="Redirect to FQDN" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^myserver$" />
<add input="{HTTPS}" pattern="^ON$" />
</conditions>
<action type="Rewrite" url="https://myserver.mydomain.com/{R:1}" />
</rule>
</rules>
</rewrite>
Even with this rule in place and enabled, when I browse to https://myserver/homepage I get the security message. What am I doing wrong with this rule?
Problem is that you have SSL only for *.mydomain.com. And when you accessing https://myserver it will return certificate error because your cert is not valid for this domain.
For better understanding about steps during SSL connection:
In your case, the problem is between step 2 and 3

IIS - Google plusone button doesn't work

Normally I Deploy my websites on servers with Apache ModRewrite using a simple rule in .htaccess to redirect the address with www to without www: www.example.com => example.com
I'm currently deploying a website on a server with Windows using IIS + UrlRewrite.
In my web.config file where you realize redirection settings I have the following rule to remove the www address:
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www\.(.+)$" />
</conditions>
<action type="Redirect" url="http://{C:1}/{R:1}" redirectType="Permanent" />
</rule>
Via browser, redirection works perfectly!
But several external tools, such as Facebook and Google+1 button, does not work when the redirection rule is active.
For example, the Google+1 button gives an error to click it (in the requisition click the button I can see the error: "code": -32099, "message": "Backend Error").
Already with Facebook realize the problem when trying to analyze the website with the www address with the following tool: http://developers.facebook.com/tools/debug
Facebook error: URL Parsing Error: Error parsing the URL typed, no data was collected.
Disabling the redirection, the Google+1 button and Facebook's analytics tool work perfectly.
Note: the principle does not inform the site because I want to leave a disabled rule to find the solution. If it is necessary to inform the link I will edit this question.
EDIT:
After some tests, regardless of the rule enabled or not my problem with the +1 button continues.
I found a thread on Google Code about the same problem, but not understand what should be done:
http://code.google.com/p/google-plus-platform/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Component%20Owner%20Summary%20Stars&groupby=&sort=&id=241
The problem occurs only bound to the site. I created a test page with two +1 buttons, one pointing to the site and pointing to Stackoverflow. By clicking the button Stackoverflow works, but not the other:
http://renalvida.org.br/teste.php

How can I indicate to users that my IIS website is undergoing maintenance?

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.

Resources