skaz
skaz

Reputation: 22580

Grails Redirect Issue with Domain Name Changing

I have a Grails application running on, let's say: www.mysite.com

In Config.groovy I have my grails.serverURL set to www.mysite.com

I use the redirect method to redirect to a certain method, but it always builds up the url using the grails.serverURL value, instead of building from the actual URL of the user. I run into a problem when someone visits the site at mysite.com, leaving off the www. Then, when they click the link that causes the redirect, they are forwarded to www.mysite.com which makes them lose their session. What should I be doing differently? Thanks!

Upvotes: 0

Views: 396

Answers (2)

David Brown
David Brown

Reputation: 3061

What webserver are you using to host the site?

Generally as a rule of thumb I always configure Apache to ensure any non www. calls are redirected to the www. equivalent.

Two lines in the Apache config or a .htaccess is all that is needed, e.g.

RewriteCond %{HTTP_HOST} ^exampledomain\.co\.uk$ [NC]
RewriteRule ^(.*)$ http://www.exampledomain.co.uk$1 [R=301,L] 

Upvotes: 2

Gregg
Gregg

Reputation: 35864

Depending on which version of Grails you're using, generally, removing the grails.serverURL from the Config completely will fix that.

Upvotes: 2

Related Questions