英文:
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:
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:
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:
<?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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论