Redirect foo.com to www.foo.com

Is there an easy way to redirect foo.com to www.foo.com in nginx?
Either that or if somebody knows a way to get restful authentication to
store a cookie for either www.foo.com or foo.com that would be great.
My current cookie is stored with this line:

cookies[:auth_token] = { :value =>
self.current_user.remember_token,:expires =>
self.current_user.remember_token_expires_at }

I tried adding :domain => ‘.foo.com’ but that didn’t seem to work. I
figure the nginx redirect would be the easiest thing…

Thanks.

Vince W. wrote:

I tried adding :domain => ‘.foo.com’ but that didn’t seem to work. I
figure the nginx redirect would be the easiest thing…

Thanks.

I’m using something like the following and it seems to work OK:

server {
    server_name www.foo.com;
    rewrite ^/(.*) http://foo.com/$1 permanent;
}

Autopendium :: Stuff about old cars
http://autopendium.com

Yeah for some reason that doesn’t work for me. After I do that and go
to foo.com it instead redirects me to one of the other vhosts on that
server. Weird.

On 9/28/07, Chris T [email protected] wrote:

self.current_user.remember_token_expires_at }
server_name www.foo.com;


support independent business – http://www.buyindie.net/

Vince W. wrote:

Yeah for some reason that doesn’t work for me. After I do that and go
to foo.com it instead redirects me to one of the other vhosts on that
server. Weird.
Did you try with

RewriteEngine On

?

Ok, the “for some reason” I mentioned below turns out to be the order
in which my vhosts were listed. The redirect always goes to the first
vhost that was setup… probably a bug in nginx or perhaps a snafu in
my config. Moving my foo.com entry to the front of the line enabled
your rewrite line to work.

Thanks,
Vince

On 9/28/07, Vince W. [email protected] wrote:

My current cookie is stored with this line:
Thanks.



support independent business – http://www.buyindie.net/

On 29 Sep 2007, at 23:03, Vince W. wrote:

Ok, the “for some reason” I mentioned below turns out to be the order
in which my vhosts were listed. The redirect always goes to the first
vhost that was setup… probably a bug in nginx or perhaps a snafu in
my config. Moving my foo.com entry to the front of the line enabled
your rewrite line to work.

nginx defaults to the first vhost when it can’t find the host so it
may well be your re-write isn’t working.

I hadn’t tried that, but I get this regardless of where I insert it:

Starting nginx: 2007/09/28 10:12:22 [emerg] 5696#0: unknown directive
“RewriteEngine” in /etc/nginx/nginx.conf:21

I tried putting it both before sendfile on; and also inside my server
block but with the same results.

-Vince

On 9/28/07, Joachim G. [email protected] wrote:


Posted via http://www.ruby-forum.com/.


support independent business – http://www.buyindie.net/

server {
    server_name www.foo.com;
    rewrite ^/(.*) http://foo.com/$1 permanent;
}

This will be working only if host end with /, and you redirect from
www.foo.com to foo.com.

Try this example:

server {
server_name foo.com;
rewrite ^(.*)$ http://www.foo.com$1 permanent;
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs