从www.m.example.com重写URl到m.example.com

时间:2015-09-07 12:46:58

标签: rewrite rule

我正在尝试在ASP.NET www.m.example.com中进行重定向,其中包含类似m.example.comawait Task.Run(() => DoMath(inData)); 的内容。我尝试了不同的方法,但无法做到。

1 个答案:

答案 0 :(得分:0)

您可以将以下内容应用于您的网页,而不是web.config

<script runat="server">

private void Page_Load(object sender, System.EventArgs e)
{
    Response.Status = "301 Moved Permanently";
    Response.AddHeader("Location","http://www.new-location.com");
}

</script>

Read more here

如果您仍想使用web.config文件,则可以执行以下操作:

  1. 在旧网页所在的目录中打开web.config
  2. 然后为旧位置路径和新目标添加代码,如下所示:

    <configuration>
      <location path="services.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/services" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
      <location path="products.htm">
        <system.webServer>
          <httpRedirect enabled="true" destination="http://domain.com/products" httpResponseStatus="Permanent" />
        </system.webServer>
      </location>
    </configuration>