簡體   English   中英

如何在asp.net中使用301重定向更改URL字符

[英]how change url character with 301 redirect in asp.net

我想對包含“產品”到“產品”的更改網址使用301重定向(差異在p中)我在頁面的page_load中使用此代碼

 if (urlAddress.Contains("products"))
        {
            HttpContext.Current.Response.Status = "301 Moved Permanently";
            Response.StatusCode = 301;
            HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().Replace("products", "Products"));
            Response.End();
        }

但是在再次重定向之后,此條件為真,並且我進入了一個循環,如何在URL中將“ P”更改為“ p”

您可以使用UrlRewrite解決此問題,

<configuration>
    <system.webServer>
        <rewrite>
            <rules>
             <rule name="LowerCaseRule">
              <match url="[A-Z]" ignoreCase="false"/>
              <action type="Redirect" url="{ToLower:{URL}}"/>
             </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

暫無
暫無

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

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