by
0
6
2,690
2
Top 1% !
Popular
Famous
Specified
Refined
OpenSource
Popularity: 5875th place
No tags for this snippet yet.
.NETFramework4.5
Architecturex86_64
Extension.cs
LanguageCSharp
MethodNameRedirectWWW
OutputTypevoid

Redirect WWW

Redirect all non-WWW Urls to WWW URLs except Localhost URL (allow you to test without unexpected redirects)
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/728768/Redirect-WWW?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public void RedirectWWW() { string theURL = Request.Url.ToString(); if (!theURL.StartsWith("http://www") && !theURL.StartsWith("http://localhost")) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Status = "301 Moved Permanently"; HttpContext.Current.Response.AddHeader("Location", "http://www." + theURL.Replace("http://", "")); HttpContext.Current.Response.End(); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus