web.config redirects only for specific domain

web.config redirects only for specific domain - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the web.config redirects only for specific domain error on your web browser. Problem :


I'm stuck with redirecting for specific domains. The setup consists of azure webapps which bring their own domain *.azurewebsites.net, I want to exclude those from redirecting. For additional domains e.g. example.com I need to redirect




  • to https

  • to www

  • and no redirection if I enter the correct address https://www.example.com



Edit:
I use deployment slots, so I want the same web.config to work when I swap a slot in production.



When I tried to use more than one rule, unfortunately I get server or redirect errors. Should I learn regex better? Here is my first rule to exclude the "internal" domains, but that is already not working:



<rule name="ignore azure" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="HTTP_HOST" pattern="^azurewebsites.net$" />
<add input="HTTPS_HOST" pattern="^azurewebsites.net$" />
</conditions>
<action type="none" />
</rule>


I have read the 30 first posts on google but none of those exclude another domain name.


Solution :

Based on Joses Answer this does what i need:
- I can access the azurewebsites domain while still on the deployment slot
- the production domain will always be redirected to subdomain with https



 <rule name="HTTPS and Subdomain in Production" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="HTTP_HOST" pattern="^.*.azurewebsites.net$" negate="true" />
<add input="HTTP_HOST" pattern="^www..*" negate="true" />
</conditions>
<action type="Redirect" url="https://www.HTTP_HOST/R:1" redirectType="Permanent"/>
</rule>


I think the rule you need is this one:



<rule name="HTTPS ignore Azure" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="HTTP_HOST" pattern="^.*.azurewebsites.net$" negate="true" />
<add input="HTTPS" pattern="^OFF$" />
<add input="HTTP_HOST" pattern="^www..*" negate="true" />
</conditions>
<action type="Redirect" url="https://www.HTTP_HOST/R:1" />
</rule>


What this rule does is check if the current domain is not in the form *.azurewebsites.net, doesn't start with www. and if it's not requested through HTTPS. If all three "ifs" apply, then it's a custom domain without www trying to be accessed through HTTP, so you send a permanent redirect (301) to the https:// version of the requested domain adding a www as a subdomain.



It should work OK. Give it a try and tell me.



HTH



If you are just trying to force HTTPS that is now a feature of Azure Web Apps without any config changes required.



How to make an Azure App Service HTTPS only



enter image description here


We hope that this article has helped you resolve the redirects, iis, azure error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=