Azure 将应用服务重定向到自定义域
Azure redirecting app service to custom domain
我正在尝试使用应用服务根目录中的 web.config 文件将默认域重定向到自定义域。
就我而言,https://default.azurewebsites.net to https://app.customdomain.com which is working but https://default.azurewebsites.net/login is not redirecting to https://app.customdomain.com
我的工作配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我也试过添加两条规则,但没有用
<rule name="Redirect rquests to default azure websites domain for login" stopProcessing="true">
<match url="(.*)/login" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/login/{R:0}" />
</rule>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/{R:0}" />
</rule>
还尝试了一个具有多个条件的规则。没用
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net/login" />
</conditions>
<action type="Redirect" url="https://https://app.customdomain.com/{R:0}" />
</rule>
与正则表达式的更多组合也尝试过,但仍然没有运气。
使用 <match url="(.*)^login" />
,对我有用。
请先查看我的测试结果
我的web.config
.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="a page" stopProcessing="true">
<match url="(.*)^a" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://jasonp2.azurewebsites.net/a.html" redirectType="Temporary" />
</rule>
<rule name="b page" stopProcessing="true">
<match url="(.*)^b" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://jasonp2.azurewebsites.net/b.html" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect default azure domain to custom domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^testing\.azurewebsites\.net" />
</conditions>
<action type="Redirect" url="https://grew.mydomain.com/login" />
</rule>
<rule name="Redirect default azure domain login url to custom domain" stopProcessing="true">
<match url="(.*)^login" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^testing\.azurewebsites\.net" />
<add input="{PATH_INFO}" pattern="^/login" />
</conditions>
<action type="Redirect" url="https://grew.mydomain.com/login" />
</rule>
<rule name="Angular rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
上面的 web.config 文件终于成功了!!!
重定向规则应定义在 angular 规则之上,并且规则名称应该是唯一的
我正在尝试使用应用服务根目录中的 web.config 文件将默认域重定向到自定义域。 就我而言,https://default.azurewebsites.net to https://app.customdomain.com which is working but https://default.azurewebsites.net/login is not redirecting to https://app.customdomain.com 我的工作配置文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/{R:0}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
我也试过添加两条规则,但没有用
<rule name="Redirect rquests to default azure websites domain for login" stopProcessing="true">
<match url="(.*)/login" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/login/{R:0}" />
</rule>
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
</conditions>
<action type="Redirect" url="https://app.customdomain.com/{R:0}" />
</rule>
还尝试了一个具有多个条件的规则。没用
<rule name="Redirect rquests to default azure websites domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net$" />
<add input="{HTTP_HOST}" pattern="^default\.azurewebsites\.net/login" />
</conditions>
<action type="Redirect" url="https://https://app.customdomain.com/{R:0}" />
</rule>
与正则表达式的更多组合也尝试过,但仍然没有运气。
使用 <match url="(.*)^login" />
,对我有用。
请先查看我的测试结果
我的web.config
.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="a page" stopProcessing="true">
<match url="(.*)^a" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://jasonp2.azurewebsites.net/a.html" redirectType="Temporary" />
</rule>
<rule name="b page" stopProcessing="true">
<match url="(.*)^b" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern=".*" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Redirect" url="https://jasonp2.azurewebsites.net/b.html" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect default azure domain to custom domain" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^testing\.azurewebsites\.net" />
</conditions>
<action type="Redirect" url="https://grew.mydomain.com/login" />
</rule>
<rule name="Redirect default azure domain login url to custom domain" stopProcessing="true">
<match url="(.*)^login" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^testing\.azurewebsites\.net" />
<add input="{PATH_INFO}" pattern="^/login" />
</conditions>
<action type="Redirect" url="https://grew.mydomain.com/login" />
</rule>
<rule name="Angular rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
上面的 web.config 文件终于成功了!!! 重定向规则应定义在 angular 规则之上,并且规则名称应该是唯一的