We recently migrated our domain from www.mohavecounty.us to www.mohave.gov. So I wrote a rule that redirects anything that comes from www.mohavecounty.us to www.mohave.gov.
The only caveat is that I need to have an exception for two URLs due to a software license tied to our original domain. So when I go to www.mohavecounty.us/console, I don't want it going to www.mohave.gov/console. The rule is working as expected for everything but the exception.
<rule name="Redirect To mohave.gov" enabled="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www.mohavecounty.us$" />
<add input="{REQUEST_URI}" pattern="^/console(.*)$" ignoreCase="true" negate="true" />
<add input="{REQUEST_URI}" pattern="^/Login.aspx(.*)$" ignoreCase="true" negate="true" />
<action type="Redirect" url="https://www.mohave.gov/{R:1}" />
</rule>
When I go to wwww.mohavecounty.us/console the page load properly, but when I look at the Chrome dev tools, I noticed that some files are coming from www.mohave.gov
The problem is that when I try to log in, its telling me that that the service I'm trying to contact is being blocked because it is a cross-domain exception.
So looking at the network tab in chrome and it seems like some files are loaded on www.mohave.gov domain instead of www.mohavecounty.us domain. I understand the reason of the problem, but what I dont understand is why are those files being loaded under www.mohave.gov instead of www.mohavecounty.us. None of the paths in question are hard coded to the domain.
I tried to seperate the exeption rule into another rule for the path console:
<rule name="ignore web forms folder 3" stopProcessing="true" enabled="true">
<match url="^console$" />
<action type="None" />
</rule>
but it's not working either.
If anyone can please help with what is wrong with my rule.
Related
I have a simple Umbraco 7.7.2 application and I'm hosting it on Azure (app-service). When I restart the server it takes 20-40 seconds for first time requesting a page which is really annoying specially when the load is high and you are Scaling out to reduce the response times.
I've tried this setting in my webconnfig, but it doesn't seem to work.
<system.webServer>
<applicationInitialization>
<add initializationPage="/page1/?warmup=1" hostName="mydomain.com" />
<add initializationPage="/page1/page2/?warmup=1" hostName="mydomain.com" />
</applicationInitialization>
</system.webServer>
I might be trying it in a wrong way, but what I did was to restart the server and I've left it for 2-3 minutes without requesting any page.
I've checked my Umbraco logs and the application wasn't even started.
Then I've requested the home page and it took 40 seconds to come up.
Then I've tried mydomain.com/page1 and it also took 20 seconds since it was the first request to access it.
*P.S: after the first request, the site is very fast and each page takes less than 100 ms to load
Update
I've implemented a rewrite to stop next redirects as Kevin has suggested.
As a result, my Umbraco will start up, but still the requests doesn't reach to the pages.
On my master page, I've added a line to write a line in the logs if it has the warmup in the querystring and it works it the page is hitted from the browser:
if (!string.IsNullOrWhiteSpace( Request.QueryString["warmup"]))
{
var pageC = Model.Content;
logger.Info(pageC.UrlAbsolute()+" "+ Request.QueryString);
}
However, there is nothing in my logs after
2018-02-08 15:16:51,245 [P7036/D2/T1] INFO Umbraco.Core.CoreBootManager - Umbraco application startup complete (took 12727ms)
2018-02-08 15:16:54,911 [P7036/D2/T1] INFO MyNamespace.Web.CustomStartup - base config done!
Here is the confing that I've added based on Kevin's answer:
<rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
</conditions>
<action type="Rewrite" url="{URL}" />
</rule>
Also, I've found another similar config on Microsoft:
<rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" />
<add input="{HTTP_USER_AGENT}" pattern="Initialization" />
</conditions>
<action type="Rewrite" url="{URL}" />
</rule>
Note that azure will warm up the URL on http, so if you are forcing https using rewrite rules, the full site will not warm up, only the redirect module will. Then it needs to finish warming up Umbraco after azure adds it into the load balancer and the first https gets through to the umbraco code. We found that out by checking the http logs when scaling out.
We couldn't figure out how to tell azure to warmup using https, so we allowed Azure to access the site on http by making a rule before our force https rewrite to stopProcessing when {REMOTE_ADDR} matches 127.0.0.*.
<rule name="Allow localhost to warmup" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{REMOTE_ADDR}" pattern="127.0.0.*" />
</conditions>
</rule>
There was so many reasons for the requests not reaching my site and thanks to Kevin and Twamley whom opened my eyes to the probable cause I could trace and find all of them.
First, as Kevin said HTTPS was one of the issues which I've fixed as below:
<rule name="No redirect on warmup request (request from localhost with warmup user agent)" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" />
<add input="{HTTP_USER_AGENT}" pattern="Initialization" />
</conditions>
<action type="Rewrite" url="{URL}" />
</rule>
Then I could see that Umbraco starts up but the requests didn't get to my pages.
<rule name="Redirect rquests to www.example.com" stopProcessing="true" enabled="true">
<match url="(.*)" />
<conditions >
<add input="{HTTP_HOST}" pattern="^example\.com$" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
I didn't expect my requests to get to this redirect since it was at the end of my rewrite rules and therefore it should be stoped at No redirect on warmup request but it didn't so I've added another condition to it: <add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" />
<rule name="Redirect rquests to www.example.com" stopProcessing="true" enabled="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^example\.com$" />
<add input="{HTTP_USER_AGENT}" pattern="Initialization" negate="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:0}" />
</rule>
Also, I have ipSecurity in my settings since it is my test environment and I didn't want it open to public. Turns out the Initialization cannot hit my site at all if I don't open up to 127.0.0.1.....
<security>
<ipSecurity allowUnlisted="false">
<add ipAddress="127.0.0.1" allowed="true" />
<add ipAddress="x.x.x.x" allowed="true" />
I like Kevin's idea of just stopping the processing as one of the first rewrite rules. I noticed his didn't have an action but you added one to yours. Maybe try his w/o an action? Is it the first rule in the file?
Another option we use is to add this condition to any problem rules (notice the negate).
<add input="{REMOTE_ADDR}" pattern="127\.0\.0\.1" negate="true"/>
Try temporarily clearing your rewrite rules until you're convinced your warmup is working, then add the rules back a few at a time to find and fix the problem redirect. Force SSL and Trailing Slash type rules will definitely cause problems.
Also, the hostName can get you in trouble easily. It should be a perfect match for your production environment. It doesn't use DNS to resolve it, it just talks to the local site and passes that in as the HOST header.
I don't have any querystrings in my warmup list. Maybe you should try dropping those. You don't really need them because you can change your logging code to:
if (Request.IsLocal && Request.UserAgent == "IIS Application Initialization Warmup") {
// log it
}
Logging them is a great idea because the warm up requests don't show up in the standard IIS logs. I have my servers mail me at the beginning and end of the warmup by hitting a special first and last entry that uses that if statement. Some useful details from Azure:
new {
WEBSITE_HOSTNAME = System.Environment.GetEnvironmentVariable("WEBSITE_HOSTNAME"),
WEBSITE_INSTANCE_ID = System.Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID"),
WEBSITE_SITE_NAME = System.Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"),
COMPUTERNAME = System.Environment.GetEnvironmentVariable("COMPUTERNAME"),
USER_AGENT = Request.UserAgent,
URL = Request.Url,
WARM_UP_TIME = (DateTime.UtcNow - _start).ToString()
}
I have a Joomla site on Azure. I have set up the .com properly and I understand why the *azurewebsites.net URL is still working.
I wanted to redirect all traffic from *azurewebsites.net to the .com. I followed this guide and it works as intended.
http://onthecloud.azurewebsites.net/seo-tip-how-to-block-the-.azurewebsites.net-domain
However, I also have an Azure CDN in place (mycdn.azureedge.net/). I use JCH Optimize to set up the CDN. I see the the calls to mycdn.azureedge.net/ are generated properly. However, somehow, because of the web.config redirect, all the traffic is redirected from the CDN back to my .com, which defeats the purpose of the CDN. This creates a lot of redirect calls.
Is there a way to write the web.config lines to exclude the CDN?
Here's what my web.config looks like. When I delete those lines, the CDN redirects disappear, so the problem is really here.
<rule name="Disable Azure Domain" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
<action type="Redirect" url="http://www.example.com{REQUEST_URI}" redirectType="Permanent" />
</rule>
Look at your conditions. You're filtering all traffic that goes to "*.azurewebsites.net". All calls to your cdn fall into that filter as well, which is why you're seeing them be redirected:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="*.azurewebsites.net" />
</conditions>
Instead, filter the calls just to your website. So your condition would look more like:
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="yoursite.azurewebsites.net" />
</conditions>
That'll let calls to the CDN go through just fine.
You can find more details on setting up redirect rules for your Azure Web App here: http://zainrizvi.io/2016/04/07/block-default-azure-websites-domain/
Fyi, below is the full web.config that I use for my site. You'll not that I've set some of the other settings a bit differently. Try using that web.config file instead (just change the site names as appropriate) and see if it works for you.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect to zainriziv.io" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^zainrizvi\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="http://www.zainrizvi.io/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Note: When you're testing the fix your browser might have cached the redirect, so you might want to try fiddler or a new browser/pc to verify things work as expected
We are using IIS URL Rewrite module to redirect all request from a mobile browser to m.mymobilesite.com by checking HTTP_USER_AGENT. This works fine and now we need to implement a "View Full Site" link which will allow the user to see the main site. Trying to achieve this by adding a "nomobile" cookie when user clicks on "View Full Site" link which will be validated and negated by the rule. For some reason my rule doesn't seems to work.
Please help.
<rewrite>
<rules>
<rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
</conditions>
<action type="Redirect" url="http://m.mymobilesite.com" appendQueryString="false" redirectType="Found" />
</rule>
</rules> </rewrite>
The rule is perfect and I figured out the issue after doing a trace on failed request at IIS level as described here
The cookie which I was creating while user select the "View Full Site" link was not created with the domain name. I added domain="mymainsite.com" on the cookie creation script and it is working fine now.
How do I use a different robots.txt for https request than the one that is used for http connections in IIS 7?
Thanks.
There are a few options here, depending on how custom you need this to be. Most flexible approach would be to write a handler and map to it for robots request, and handle internally.
However, for most needs, try to URL rewrite module
http://www.iis.net/download/urlrewrite
off top of my head (aka prob doesnt work 100%), its something like :
<rule name="https_robots">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/robots-https.txt" />
</rule>
Got exactly the same problem:
I am setting up https version now, want to look at it and debug it without a rush, meanwhile fending off Google from crawling https, but keeping http "business as usual". Here's the piece of code I used in a config file:
<rule name="https_robots" stopProcessing="true">
<match url="^robots\.txt$" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Rewrite" url="robots_https.txt" />
</rule>
A few notes:
Basically, I've created a file "robots_https.txt" containing "disallow for all" instruction.
I used Rewrite, not Redirect. I am not sure if the spider would get the redirect. I really doubt that. With Rewrite you can't go wrong.
Hope that helps!
I've been using the UrlRewrite IIS plugin for about a month on our production site.
I created a single redirect rule using the supplied template/wizard, the resulting config enrty is as follows:
<rewrite>
<rules>
<rule name="CanonicalHostNameRule1" enabled="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.mycompany\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.mycompany.com/{R:1}" />
</rule>
</rules>
</rewrite>
It's been running fine until this morning, when the site started erroring with "too many redirects". As far as I know, nothing in the configuration or infrastructure changed.
I disabled the rule, and the site became functional again (though clearly without any redirecting).
I then re-enabled the rule, and now all is running as expected. I didn't make any changes to the rule other than to temporarily disable it.
Any ideas? Is the plugin buggy?
I'd recommend setting this up:
http://learn.iis.net/page.aspx/467/using-failed-request-tracing-to-trace-rewrite-rules/
This may help you track down the problem if you start getting the "too many directs" error again.
Try this other code, i have on my web and run perfect:
<rule name="Canonical Host Name" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^yourdomain\.com$" />
</conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:0}" redirectType="Permanent" />
</rule>
The explanation is simple:
Match any URL received to process
The condition is that have anydomaintext.extension (your domain and extension) without prefix
Redirect to same domain with full prefix and put all url.
Other tries was R:1 but quit some of the main url and not run.
The sample from Ruslani:
http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx
I tried to use adding www but finally use the sample above.
The fix below worked for me. I discovered my rewrite rule was at out-of-date. The other domain had changed their URL policy and were now redirecting all traffic from otherdomain.com to www.otherdomain.com
<action type="Rewrite" url="http://otherdomain.com/abc/{R:1}" />
to
<action type="Rewrite" url="http://www.otherdomain.com/abc/{R:1}" />
Do you see the difference? By adding the 'www' I preempted the other domain redirection. I basically just complied with their new policy.