I have to take a site down for maintenance, and need a site down page.
I have come across the app_offline.htm page, which seems to do what I want.
However, when I put it on one of the test sites it did not work properly and required a bit of extra work to get it working properly.
Given this, and the fact that I cannot test it on the live site, I am trying ot create a backup plan.
So I have the following web.config rule:
<rule name="Site Down Rule" stopProcessing="true">
<match url="(.*)"/>
<conditions/>
<action type="Redirect" url="app_offline.html" />
</rule>
Which should redirect to the custom page.
The problem is that it gives the following error: ERR_TOO_MANY_REDIRECTS, which I assume is because when it reaches the given page, it still tries ot redirect.
But I do not know how to solve this. I have seen this question:HTTP redirection issue in IIS, keep getting ERR_TOO_MANY_REDIRECTS on the browser
and the related question it references, but these do not provide a working solution.
Any ideas?
EDIT:
Is it possible to add an exclusion to this rule - which says do not redirect given page
Got it - I just needed to exclude the page that was being redirected to:
<rule name="Site Down Rule" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{REQUEST_URI}" negate="true" pattern="app_offline.html" ignoreCase="true" />
</conditions>
<action type="Redirect" url="app_offline.html" />
</rule>
Related
The main problem is specified in the title; however, it is a little more nuanced than that.
I cannot give away the exact address, but the URL has the syntax: https://name.mywebsite.com.
If I go to that exact address, the page will load as intended. If I try to be more specific about where exactly I want to go on the page - let's say to: https://name.mywebsite.com/home - I get a blank page.
Curiously enough, after I go to https://name.mywebsite.com, all the other addresses work as well and either redirect me to that address or display the site that they are supposed to show. I figured out that some necessary Cache-Data and data for the local storage are not set if I don't call the site over the mentioned address.
All of that wouldn't be much of a problem, since only the first call of the website is affected. However, most users of the site will first call it with a QR-Code (which leads to a specific sub-page of the site), and it wouldn't be very nice if they are greeted with a blank page.
Also, it is a .NET Core App with Angular Frontend.
I can reproduce the error by clearing my cache and cookies. The necessary data is no longer set and all domains will display a white page - except https://name.mywebsite.com - again.
I think I understood the problem, but I cannot seem to come up with a solution. I tried some changes in the IIS Manager on the server, but to no avail. My main bet was to apply an inbound rule with the URL Rewrite function, but that did not work.
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect from first shop open" enabled="false" stopProcessing="true">
<match url=".*" />
<action type="Redirect" url="https://name.mywebsite.com/" appendQueryString="true" logRewrittenUrl="true" redirectType="Found" />
</rule>
</rules>
</rewrite>
</system.webServer>
I also tried that rule with all possible Redirect types. Those rules do alter the page, but not in the way I want it. Instead of the blank white page I get an error that the redirect failed (with the hint that it is probably due to a lack of cookies). That error applies to all pages, even https://name.mywebsite.com. So I have no way of accessing the website now.
I also tried to find any other configuration that might prevent other URLs from loading the data, but I did not find anything like that either (or I simply looked at the wrong places).
Edit: /home would be a route in Angular. Also, the only rewrite rule that exists and that I tried is the one shown in the picture (which I updated so that it fits better with the question). I made some changes to the question in general.
As it turns out, I simply had to make some changes to the rule I posted in the question. Changing the Redirect to a Rewrite that targets /index.html and adding some conditions (which should be adapted to your personal needs) did the trick and the website no longer shows a blank page.
The link from Lex Li in the comments from the questions angular.io/guide/deployment#fallback-configuration-examples and the link https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference#accessing-url-parts-from-a-rewrite-rule helped me building the correct rule.
<rewrite>
<rules>
<rule name="Angular Routes" enabled="true" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="true">
<add input="{REQUEST_URI}" pattern=".*/(home|item.*)" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" logRewrittenUrl="false" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name=".*" />
</rewriteMaps>
</rewrite>
I am working with DNN website, which works with different domains, i mean to say one website is working with multiple domains, layout and pages all categorizes with Different portals. every Portal has its own pages and content. Now i have to write some rewrite rules for the different portal. for main portal i have used the following concept to write the rule :
<rule name="r7" stopProcessing="true">
<match url="^vows/tabid/(.*)id/([0-9]+)/Default.aspx" ignoreCase="true"/>
<action type="Redirect" url="/plan/brochure.aspx"/>
</rule>
Now for another domain(portal) example www.abc.uk.co. how can i write rules for this portal. if i write the URL in rule it does not work for me. and if i write in the above format then it cause to redirect for first domain also.
Please help me how can i achieve my goal. any kind of help will be appreciated. Thank you
here is the code worked for me:
<rule name="Uk1" stopProcessing="true">
<match url="^man/mostpopulararticles/brides.aspx" ignoreCase="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www.)?abc.co.uk$" />
</conditions>
<action type="Redirect" url="/man.aspx" />
</rule>
Thanks All
you can use Url Rewriting feature of dotnetnuke you can get detail on this link
http://www.dnnsoftware.com/wiki/page/url-rewriting
you have write rule in below path
Config\SiteUrls.config
<RewriterRule>
<LookFor>.*testwebserice.asmx(.*)</LookFor>
<SendTo>/DesktopModules/Projectname/Web service/testwebserice.asmx$1</SendTo>
</RewriterRule>
For better SEO we are using URL rewrite to convert all the URL's to lowercase. I set this one as mentioned in this the below article.
Everything is working fine from URL perspective, but we see lot of 301 redirects when we check in fiddler.
It looks like the images, javascript, css, jquery ajax calls and everything is getting converted into lower case.
I am trying to remove that and want to rewrite only aspx extension and no extension urls. I tried to play around the matchurl without any success. Any help or guidelines will be highly appricated.
Thanks
Edit:
My Current rule is
<rules>
<rulename="LowerCaseRule1"patternSyntax="ExactMatch"stopProcessing="true">
<matchurl="[A-Z]"ignoreCase="false"/>
<actiontype="Redirect"url="{ToLower:{URL}}"/>
</rule>
</rules>
You could probably use something as follow:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
<conditions logicalGrouping="MatchAny">
<add input="{REQUEST_FILENAME}" pattern="\.aspx$" />
<add input="{REQUEST_FILENAME}" pattern="\." negate="true" />
</conditions>
</rule>
The rule will be triggered only if one of the condition is true:
The first one checks if the requested path (filename) ends with .aspx.
The second one checks if the if the requested path (filename) doesn't contain a . (so doesn't have an extension)
I recently got a SSL certificate for my website and want to redirect all traffic to HTTPS. I got everything to go to https://mydomain.com but if someone enters http://mydomain.com/anotherpage it drops the other page and just takes the user to the home page.
My rule in my web.config file looks like this:
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
</rule>
I also tried https://{HTTP_HOST}{REQUEST_URI} without any success. Can anyone tell me what I need to do to make the website redirect to the proper HTTPS version of the page? I have a feeling it has something to do with the pattern, but I can't seem to figure out the syntax.
I found a way to do this, and you don't need the Rewrite module for it. The following worked for me on Windows 8 (IIS 8.5):
Remove the HTTP binding from your site (leave HTTPS in place)
Add another site
Make sure that the new site has HTTP binding
Configure HTTP Redirect as shown:
Now all HTTP request will redirect to your HTTPS site and will preserve the rest of the URL.
Change it to:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
I had the same problem where the R:1 was dropping my folders.
I fixed it like this.
<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}"
appendQueryString="false" redirectType="SeeOther" />
</rule>
I can't comment yet or I'd leave this as a comment under AndyH's answer. The solution was correct, though I hit a single further snag (likely tied to the use of Adobe's Coldfusion server). I wanted to share some further research I had to do for any other unfortunate soul who may run into it.
Once set up, the redirect would always end at this url:
https://xxx.xxx.com/jakarta/isapi_redirect.dll
The fix for this was found in an Adobe thread (https://forums.adobe.com/thread/1034854): I had to change an application pool's settings as follows:
Real site (HTTPS binding only, actually contains code and virtual directories)
Application pool's Advanced Settings: Enable 32-Bit Applications : False
Http_Redirect site (HTTP binding only, is a blank shell of a folder with no directories)
Application pool's Advanced Settings: Enable 32-Bit Applications : True
EDIT: Another detail, tied to query string preservation:
Per suggestion in this post (http://www.developerfusion.com/code/4678/permanent-301-redirect-with-querystring-in-iis/)
Add $S$Q at the end of the domain and make sure the box for Redirect all requests to exact destination is checked. Then it will save the query string as well.
I believe AndyH's answer to be the easiest and best way. I have found using the URL rewrite can also conflict with code that may redirect the user to another page. IT commonly broke in our environment. But Andy's solution worked flawlessly. I also think Andy's solution will put less overhead on the server as it doesn't need to examine every url hitting it for possible re-write conditions.
I found a workaround:
Consider what in IIS is consired a website: simply a set of rules, the path in which get files and its bindings.
Furthermore, there's available a function called "HTTP Redirect" (included standardly in IIS), that redirect an host to another, keeping all subdirectory (it makes a relative path). The workaround is to leave just the binding for HTTPS (port 443) in your website, and create another with the binding on HTTP (port 80) and set for this an HTTP redirect to your URL with https://.
For example, consider a website called mytest and its urls http://www.mytest.com/ and https://www.mytest.com/.
Set for it instead only binding on https://www.mytest.com/, and delete the http binding. Then create a new website with the same local path, called mytest http with just a binding over port 80 (http://www.mytest.com/) and set for this one an HTTP Redirect to https://www.mytest.com/.
Simple and clean, and that should be as fast as directly the https url for the user, because it's just an internal redirect. I hope that can work for you!
You can add the URL Rewrite module to IIS (IIS 7 or higher) which allows you to add create the redirect in a visual way. The module can be downloaded here.
This step-by-step tutorial worked wonders for me and explains that when using this module, all it actually does is add some code to your web.config file as such:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>
</rules>
</rewrite>
I have found that the
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
syntax will only work for the website's ROOT web.config file.
If the rewrite rule is applied to a virtual web.config file, then use..
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{URL}" />
The {URL} syntax will include the initial forward slash, the virtual path, and any URL parameters.
I was trying to play with URL re-writing using the Rewrite Module 2.0 but I had no luck getting it to work. What I'm trying to do is re-write all calls to web app at port 80 to other applications hosted in IIS (or maybe on different servers on the network). Using the GUI provided by IIS I created the following rule:
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="site1/(.*)" />
<action type="Rewrite" url="http://localhost:7001/{R:1}" />
</rule>
</rules>
</rewrite>
Quiet simple, but unfortunately it does not work. On the other hand, when I change the action type to Redirect, it works fine.
What could be the problem?
I ran into this same issue yesterday, and it took me a long time to figure out.
The key here is that you've got an http:// prefix in your rewrite action; that makes this a special case that needs to be handled by Application Request Routing. The first step is to make sure that the Application Request Routing module is installed. You can find the module at https://www.iis.net/downloads/microsoft/application-request-routing. Once that is installed, go to your IIS web server (a level up from your web site), and open the Application Request Routing Cache feature. From the actions on the right, choose Server.Proxy.Settings, and make sure that the "Enable Proxy" checkbox is checked. This allows the URL rewrite task to be re-routed to Application Request Routing, and your reverse proxy should work for external requests.
The idea came from this excellent blog post from 2009: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/
Stumbled across this old post when I was trying to solve the same issue.
SOLVED!
Using Rewrite URL feature in IIS Services Manager I created a friendly URL rule.
This worked ok and when I looked at the rule in the web.config file (www root) it showed 1 rule to redirect and 1 rule to rewrite.
I edited this to suit 1 match. Then I just duplicated this code editing the product ID for each. Example below:
<rule name="RedirectUserFriendlyURL1" stopProcessing="true">
<match url="^product\.php$" />
<conditions>
<add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
<add input="{QUERY_STRING}" pattern="^id_product=\b35\b" />
</conditions>
<action type="Redirect" url="990mm-bohemia-cast-iron-electric-radiator"
appendQueryString="false" />
</rule>
The first rule looks for the string "product.php" in the URL and "id_product=35", it then redirects to "990mm-bohemia-cast-iron-electric-radiator" which currently does not exist. Then (see below)
<rule name="RewriteUserFriendlyURL1" stopProcessing="true">
<match url="^\b990mm-bohemia-cast-iron-electric-radiator\b" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="product.php?id_product=35" />
</rule>
This rule rewrites the "product.php?id_product=35" bit to `990mm-bohemia-cast-iron-electric-radiator", creating the new location for the redirect.
Do make sure MVC routing doesn't steal your request. To prevent that from happening, ignore the route you're trying to rewrite:
RouteTable.Routes.Ignore("blog/{*pathInfo}");
Inspired by: https://sitecore.stackexchange.com/questions/3645/how-to-setup-a-reverse-proxy-with-sitecore
Change the Rewrite URL to AbsolutePath instead putting http://...
it should be
<action type="Rewrite" url="{R:1}" />
It worked for me, but in my case, I have been rewrite to a fixed webpage.