大网数据广告活动
网站运营与故障问答

web.config redirects only for specific domain

· 52CE 我爱测

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 r…

问题原文

原帖链接 · 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>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2018-07-05)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。