Search code examples
grailsspring-securitygrails-2.0grails-plugingrails-controller

How to always set "www" in grailsUrl?


Config.groovy

grails.serverURL = "http://www.changeme.com"

i set my grails url with "http://www.changeme.com"

in this.. when i type changeme.com its shows me a correct page, but when i am trying to login with http://changeme.com its redirecting me to same login page with http://www.changeme.com and when i logged in through this url then its redirecting me to my page..

So how i set always "www" in my URL.. if someone just type changeme.com


Solution

  • You have to create a filter like this..

     class HostFilters {
    
       def filters = {
        all(controller:'*', action:'*') {
            before = {
                if(request.getHeader("host") =="changeme.com" )
                {
                 redirect(url: "http://www.changeme.com")
    
                }
            }
    
        }
    }