簡體   English   中英

如何在web.config文件(iis 7.5)中重寫URL?

[英]How do rewrite the url in web.config file(iis 7.5)?

輸入:domainname.com/name

輸出:domainname.com/page.aspx?n=name

我嘗試了下面的代碼。

<rewrite>
    <rules>
        <rule name="RedirectToWWW" stopProcessing="true">
            <match url=".*" ignoreCase="true" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^domain.com$" />
            </conditions>
            <action type="Redirect" url="page.aspx?n={R:0}" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

它很酷。 但是如果我只輸入域名,那也要重寫。如何避免這個問題?

Oh my god ! finally got the solution.
<rewrite>
    <rules>
        <rule name="RedirectToWWW" stopProcessing="true">
            <match url="^(.+)$" />
        <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Redirect" url="page.aspx?n={R:0}"/>
        </rule>
    </rules>
</rewrite>

暫無
暫無

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

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