[英]how change url character with 301 redirect in asp.net
i want to use 301 redirect for change url that contain "Product" to "product" (difference is in p) i use this code in page_load of page 我想对包含“产品”到“产品”的更改网址使用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();
}
but after redirecting again this condition is true and i go in a loop how can change "P" to "p" in URL 但是在再次重定向之后,此条件为真,并且我进入了一个循环,如何在URL中将“ P”更改为“ p”
you can solve this by using UrlRewrite
, 您可以使用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.