簡體   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