Monday, May 02, 2011

Grails Subdomain Redirects

Since I'm using Cloudbees Run@Cloud service to host Scripty Note, I don't have access to their nginx configuration files (somewhat annoying). Since the nature of ScriptyNote is to be small, then we need to automatically remove the 'www' subdomain on any incoming requests and 301 redirect back to the no-www url. I posted a question here on stackoverflow and a very nice gentleman let me in on the Grails Filters convention. So here's the code I ended up implementing to redirect from 'www.scriptynote.com' to 'scriptynote.com'.


There it is. By convention, as long as this class ends with Filters and is sitting in grails-app/conf, it will be picked up. Also, it would be easy enough to do some switching around in the code and you can produce the opposite effect as needed.

No comments: