【问题标题】:How to create web.config URL Rewrite to redirect a subdomain to a pageroute如何创建 web.config URL 重写以将子域重定向到页面路由
【发布时间】:2015-02-16 00:40:32
【问题描述】:

我想在 web.config 上创建一个重写规则,例如 subdomain.domain.com 到 www.domain.com/abc/xyz 并在浏览器栏上保留 url subdomain.domain.com。 我怎样才能做到这一点?我尝试了很多配置,但似乎这是不可能的。

以下是我尝试过的示例:

<rewrite>
  <rules>
    <rule name="SubDomain" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="^(?!www)(\w+)\.domain\.com$" />
      </conditions>
      <action type="Rewrite" url="http://www.domain.com.com/abc/xyz" />
    </rule>
  </rules>
</rewrite>-->

【问题讨论】:

    标签: c# asp.net iis web-config url-rewrite-module


    【解决方案1】:

    这应该可行:

    <rule name="SubDomain" stopProcessing="true">
    <match url="(.*)" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="(.*).domain.com" />
        </conditions>
        <action type="Rewrite" url="/abc/xyz" />
    </rule>
    

    【讨论】:

    • 这种方法的问题是页面 /abc/xyz 将尝试以 subdomain.domain.com/style.css 的形式打开所有相关内容。我通过将所有内容引用更改为绝对 URL 来解决问题。谢谢你的帮助。
    猜你喜欢
    • 2021-03-02
    • 1970-01-01
    • 2020-04-27
    • 2016-03-23
    • 2021-08-08
    • 2021-11-18
    • 2016-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多