【问题标题】:How to rewrite and/or redirect a url in web.config如何在 web.config 中重写和/或重定向 url
【发布时间】:2016-09-01 23:04:56
【问题描述】:

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

我需要设置一个子域(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 文件中输入什么重写规则来实现这一点。或者也许有更好的方法。

谢谢。

【问题讨论】:

    标签: asp.net-mvc azure url-rewriting web-config url-redirection


    【解决方案1】:

    你可以试试这个吗?

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

    【讨论】:

    • 当然想。感谢您的帮助
    • 以防万一这对您有用,您能否将答案标记为正确?谢谢
    • 这行不通。它实际上搞砸了网站。阅读了一些关于重写规则的内容让我意识到上面的内容会将所有内容重定向到子域,这不是我想要的。
    猜你喜欢
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-19
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    相关资源
    最近更新 更多