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
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
you can solve this by using 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.