簡體   English   中英

僅重定向根文件夾 web.config 上的 default.aspx

[英]Redirect only default.aspx on the root folder web.config

http://foo.com/Default.aspx

http://foo.com/about/Default.aspx

http://foo.com/random/Default.aspx

                <rule name="Default Document" stopProcessing="true"> 
                  <match url="(.*)default.aspx" /> 
                  <action type="Redirect" url="{R:1}" redirectType="Permanent" /> 
                </rule>

這會將所有 /Default.aspx 重定向到 /

我只需要根目錄上的 Default.aspx 重定向到 /。 那怎么辦呢? TIA

最后,能夠讓它工作。

            <rule name="root home" stopProcessing="true" patternSyntax="ExactMatch">
                <match url="Default.aspx" ignoreCase="true"  /> 
                <action type="Redirect" url="/" redirectType="Permanent" /> 
            </rule>

patternSyntax="ExactMatch" 是解決問題所需要的。 謝謝你的幫助。

您可以在正則表達式中包含域名而不是 (.*)

<rule name="Default Document" stopProcessing="true"> 
              <match url="(.*)foo.com/default.aspx" /> 
              <action type="Redirect" url="{R:1}foo.com" redirectType="Permanent" /> 
            </rule>

foo.com/default.aspx 正則表達式測試結果

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM