问题原文
原帖链接 · lolops · CC BY-SA 4.0
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.
已采纳解答
原帖链接 · lolops · CC BY-SA 4.0
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>
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
