繁体   English   中英

如何在web.config中重写和/或重定向URL

[英]How to rewrite and/or redirect a url in web.config

这是我的问题。 我需要两件事:

我需要设置一个子域(sub.example.com)以从http://example.com/somepath加载其内容,但是该URL需要为用户保留(sub.example.com) 这将使http://example.com/somepath/someotherpath等同于sub.example.com/someotherpath ,依此类推...

而且,如果用户直接访问http://example.com/somepath ,我要么需要将其重定向到子域,要么只需重写URL。

我正在使用Azure上托管的MVC Web应用程序。

我写重写规则不好。 因此,如果有人可以帮助我,如果可能的话,需要什么重写规则才能输入到我的web.config文件中以实现此目的。 也许有更好的方法。

谢谢。

你可以尝试一下吗?

<rewrite>
  <rules>
    <rule name="Redirect" stopProcessing="true">
      <match url="(.*)" />
      <action type="Redirect" url="http://sub.example.com/{REQUEST_URI}" redirectType="Found" />
    </rule>
  </rules>
</rewrite>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM