Created
May 3, 2011 15:47
-
-
Save outdooricon/953585 to your computer and use it in GitHub Desktop.
Strip all requests with www subdomain and 301 redirect.
This file contains hidden or 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
class DomainFilters { | |
def filters = { | |
wwwCheck(uri:'/**') { | |
before = { | |
if (request.getServerName().startsWith("www.")) { | |
int port = request.getServerPort(); | |
if (request.getScheme().equals("http") && port == 80) { | |
port = -1; | |
} else if (request.getScheme().equals("https") && port == 443) { | |
port = -1; | |
} | |
URL redirectURL = new URL(request.getScheme(), request.getServerName().replaceFirst("www.",""), port, request.forwardURI); | |
response.setStatus(301) | |
response.setHeader("Location", redirectURL.toString()) | |
response.flushBuffer() | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment