Last active
December 15, 2015 14:59
-
-
Save waldyrfelix/5278764 to your computer and use it in GitHub Desktop.
redirects domain.com to www.domain.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Regex.IsMatch(Request.Url.AbsoluteUri, @"^((http|https)://[^www]).*$")) | |
{ | |
string newDomain = String.Format("{0}://www.{1}{2}", | |
Request.Url.Scheme, | |
Request.Url.Authority, | |
Request.Url.AbsolutePath); | |
Response.Status = "301 Moved Permanently"; | |
Response.AddHeader("Location", newDomain); | |
Response.End(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Eu faria assim
Com a regex atual: ^((http|https)://[^www]).*$
Um domínio assim: http://wordpress.com não daria um match
Detalhe o [] significa qual caracteres serão permitidos, e usando ^ como primeiro caractere dele vai ser negando os caracteres, então:
[w] == [www] => true
[^w] == [^www] => true