Azure App Service:将所有域名重定向到相同的 .com 域名。

huangapple go评论53阅读模式
英文:

Azure App service: Redirect all domains to the same .com Domain

问题

以下是您要翻译的内容:

"I am hosting a website in Azure App service.
I registered many domains to point all to the same IP Address:

example.com
example.ch
example.de
example.asia
...

I want that all Domains will point to the same url:

www.example.com

So if a user navigates to example.net, the browser should send him to www.example.com.

I tried to do this with adding a rule to my webconfig:
























This works only half.
If I navigate to example.com, it navigates to www.example.com.
But if I navigate to example.net, it navigates to www.example.net.
Is my pattern ^example.(.*)$ valid?

Strange.
Can you tell me the best approach to do this? Is the webconfig even a good start? Or are there any settings in the app service itself for such a configuration?"

英文:

I am hosting a website in Azure App service.
I registered many domains to point all to the same IP Address:

example.com  
example.ch  
example.de  
example.asia  
...  

I want that all Domains will point to the same url:

www.example.com

So if a user navigates to example.net, the browser should send him to www.example.com.

I tried to do this with adding a rule to my webconfig:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxQueryString="32768"/>
            </requestFiltering>
        </security>
        <rewrite>
            <rules>
				<rule name="RedirectNonWwwToWww" stopProcessing="true">
				  <match url="(.*)" />
				  <conditions>
					<add input="{HTTP_HOST}" pattern="^example.(.*)$" />
				  </conditions>
				  <action type="Redirect" url="http://www.example.com/{R:0}" redirectType="Permanent" />
				</rule>
               
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

This works only half.
If I navigate to example.com, it navigates to www.example.com.
But if I navigate to example.net, it navigates to www.example.net.
Is my pattern ^example.(.*)$ valid?

Strange.
Can you tell me the best approach to do this? Is the webconfig even a good start? Or are there any settings in the app service itself for such a configuration?

答案1

得分: 0

以下是翻译好的内容:

我可以自己回答这个问题。
这是满足我的需求的 solution web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.web>
        <httpRuntime maxQueryStringLength="32768" maxUrlLength="65536"/>
    </system.web>
    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxQueryString="32768"/>
            </requestFiltering>
        </security>
        <rewrite>
            <rules>
                <rule name="Redirect to www.xxx.com">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^(example\.com|example\.net|example\.asia|example\.cn|example\.com\.cn|example\.net\.cn|example\.de|example\.hk|example\.co\.in|example\.in|example\.com\.sg|example\.com\.tw|example\.tw)$" />
                    </conditions>
                    <action type="Redirect" url="https://www.example.com/{R:0}" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
英文:

I can answer the question myself.
This is the solution web.config for my requirements:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;httpRuntime maxQueryStringLength=&quot;32768&quot; maxUrlLength=&quot;65536&quot;/&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
        &lt;security&gt;
            &lt;requestFiltering&gt;
                &lt;requestLimits maxQueryString=&quot;32768&quot;/&gt;
            &lt;/requestFiltering&gt;
        &lt;/security&gt;
        &lt;rewrite&gt;
            &lt;rules&gt;
				&lt;rule name=&quot;Redirect to www.xxx.com&quot;&gt;
				  &lt;match url=&quot;.*&quot; /&gt;
					  &lt;conditions&gt;
						&lt;add input=&quot;{HTTP_HOST}&quot; pattern=&quot;^(example\.com|example\.net|example\.asia|example\.cn|example\.com\.cn|example\.net\.cn|example\.de|example\.hk|example\.co\.in|example\.in|example\.com\.sg|example\.com\.tw|example\.tw)$&quot; /&gt;
					  &lt;/conditions&gt;

				  &lt;action type=&quot;Redirect&quot; url=&quot;https://www.example.com/{R:0}&quot; redirectType=&quot;Permanent&quot; /&gt;
				&lt;/rule&gt;              
            &lt;/rules&gt;
        &lt;/rewrite&gt;
    &lt;/system.webServer&gt;
&lt;/configuration&gt;

huangapple
  • 本文由 发表于 2023年6月5日 16:44:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404774.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定