Azure WebApp Subdomain Rewrite - azure

I have what should be a simple rewrite URL, that takes our subdomain and rewrites it to a path on our main website. This works fine locally in IIS. However, it does not work within our webapp, any suggestions on how to point a subdomain to a folder in Azure? All the custom domains and certs are wired up correctly in Azure, and we have several other rules that are working, just not this one for the subdomain rewrite.
<rule>
<match url="*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="*://oursubdomain.*/*" />
</conditions>
<action type="Redirect" url="{C:1}://ourwebsite.com/oursubdomain/{C:3}" redirectType="Permanent" />
</rule>
Thanks for the help

It appears you have to be explicit when rewriting sub domains inside of Azure. As
Azure is already using wildcard to map the sub doamain. Replacing pattern="://oursubdomain.*/" with pattern="^oursubdomain.ourdomain.com$" the rule now works correctly.

Related

IIS URL Rewrite for one spesific domain

I have a rewrite rule that redirects users from mydomain.com/reset/test123 to mydomain.com/module.aspx?key=test123.
The rule works fine, and look like this:
<rule name="Reset" stopProcessing="true">
<match url="^reset/([_0-9a-z-]+)" />
<action type="Redirect" url="/module.aspx?key={R:1}" appendQueryString="false" />
</rule>
The only problem is that my website has multiple domains, and the rule runs for all of them. I need the rule to only run for mydomain.com.
I tried to change the match url to ^mydomain.com/reset/([_0-9a-z-]+), but this don't work.
How can I make the redirect to only run for one spesific domain?
Just add a condition under your <rule> element:
<conditions>
<add input="{HTTP_HOST}" pattern="mydomain.com" />
</conditions>
See Documentation

Route 53 Strip WWW from All URLs

I need to remove WWW. from all my URLs on route 53. I have a web.config rewrite rule on my website that works with my Azure VMs but when converting to webapps it is not allowed. A mistake in the past informed users that their personal website was www.john.domain.com or www.jane.domain.com. With the Rewrite rule on it works going to VMs in azure but not to Webapps. I am looking to remove the extra www. from all url requests. I am using Route 53 for DNS and I have a Redirect rule for Naked DNS domain.com already to go to www.domain.com but I would like to have another redirect or rewrite that works like the web.config rule.
<rule name="Remove www from 4th level" stopProcessing="true">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
</conditions>
<action type="Redirect" url="http://{C:1}/{R:0}" statusCode="200" statusReason="Ok"/>
</rule>
You're missing the http/https from your pattern. Your conditions should look more like:
<conditions>
<add input="{HTTP_HOST}" pattern="^http://www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
<add input="{HTTP_HOST}" pattern="^https://www\.([^\.]+\.[^\.]+\.[^\.]+)$"/>
</conditions>

Azure forcing https for no reason?

TL;DR Changing my web.config file does nothing and HTTPS is forced on all domains despite that the entire rule is removed from web.config
Long version:
I previously read this tutorial on how to configure https on your azure web-app and force it to deliver only https content:
https://azure.microsoft.com/sv-se/documentation/articles/web-sites-configure-ssl-certificate/
Now, I want to change so that some subdomains do not force https, I read about it and was told that you could add this line to your web.config to remove the rule form certain domains:
<rule name="Force HTTPS" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions>
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="^subdomain\.mydomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
That all seemed nice, but I couldn't get it to work. Now, here's when it gets weird:
As a troubleshoot step, I removed the entire "Force HTTPS"-rule from my web.config, and azure STILL forces HTTPS on all domains. It still works for the normal domain, but for all subdomains that do not have certificate files I'm given an error response when I try to connect. It's as if the web.config file is cached, meaning that all domains are looking for certificate files and those that cannot find any that match them just report back that something is wrong.
When I try to visit subdomains, this is the response I get:
Looking at your web.config file, in the last line you set redirectType="Permanent". I suspect what you're seeing is an artifact of your browser caching the redirect settings.

IIS Rewrite Map not working

I'm rebuilding a site using iis urlrewriting on both static and dynamic pages. The redirects are all working well. The rewrite module is working perfectly.
Since the site structure is changing, I need to be able to redirect "old" defunct urls to new pages. So, for example, www.sitename.com/research.asp needs to be redirected to www.sitename.com/news
I've followed the instructions to set up a rule using a rewrite map and placed the rule near the top of my webconfig file (just under the CanonicalHostNameRule). But whatever permutations I've tried in the rule, I just can get it to work. The redirects don't happen - I just get a 404 for the (non-existent) .asp page. The map just seems to be getting ignored entirely. Just to re-iterate, all my other rules are working fine.
I've tried turning off all other rules and just working with this one, but no luck. Equally, I've trawled this forum and others for suggestions (using REQUEST_URI rather than Filename, restarting IIS, recycling App. Pools, etc etc), but nothing seems to work. The "Redirect" url="{C:1}" just sends me back to the old asp page I'm trying to get redirected away from, if that makes sense. Nothing in FailedRequestTracing seems to help, either.
Am I missing something very obvious here?
The Rule:
<rule name="Redirect Rule" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{StaticRedirects:{REQUEST_FILENAME}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="{C:1}" appendQueryString="false" redirectType="Permanent" />
</rule>
The Map:
<rewriteMaps>
<rewriteMap name="StaticRedirects">
<add key="research.asp" value="news" />
<add key="blog.asp" value="news" />
<add key="mentors.asp" value="interviews" />
<add key="regulars.asp" value="opinion" />
</rewriteMap>
</rewriteMaps>
NB - there are lots of other static redirects to add to this once it actually works, which is why I wanted to use a map.

Azure Web Sites custom domain

I configured a custom domain for my Azure Web Site using CNAME records.
Everything works fine, except for the fact that I can access my site using both *.azurewebsites.net and *.com.
Isn't this a SEO issue, and can it be avoided so that I get *.com in both cases?
You can try with simple url rewrite rule in your web.config file:
<system.webServer>
<rewrite>
<rules>
<rule name="MyHostNameRule">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://domain.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
Basically, it says that if request host doesn't match specified pattern, just rewrite it to domain.com/... If you have access to the IIS, you can use Url Rewrite module there, where this code can be created through a wizard.
One hint: when developing app and testing on localhost:port, it will rewrite url. To avoid that, put this rewrite rule in Web.Release.Config, and of course deploy your app to Azure WebSite in Release mode! Only thing you need is add xdt:Transform to rewrite element:
<rewrite xdt:Transform="Insert">

Resources