Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: NginX Rewrites
PostPosted: Thu Feb 05, 2009 2:58 pm 
Offline
Newbie

Joined: Wed Nov 26, 2008 6:42 am
Posts: 2
I'm happily running a site using Nginx. In my server conf I use:

Code:
server {

            listen   80;
            server_name  www.foo.com;
            rewrite ^/(.*) http://foo.com/$1 permanent;

           }


to strip the www part of the domain.

I also own the domain foo.co.uk. What I want to do is have visitors to foo.co.uk redirected to foo.com. So, would the following work or do I have to brush up on my Regex:

Code:
server {

            listen   80;
            server_name  foo.co.uk;
            rewrite ^/(.*) http://foo.com/$1 permanent;

           }

server {

            listen   80;
            server_name  www.foo.co.uk;
            rewrite ^/(.*) http://foo.com/$1 permanent;

           }


Top
   
 Post subject:
PostPosted: Thu Feb 05, 2009 3:23 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
Your regex is the same in all cases
^/(.*)
which means "beginning of line, followed by a / and then rember everything else as $1. So "/hello/there" would make $1="hello/there". Your redirect then rewrites that as http://foo.com/$1 (so http://foo.com/hello/there) with a permanent redirect response in the HTTP headers.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
 Post subject:
PostPosted: Thu Feb 05, 2009 4:37 pm 
Offline
Senior Newbie

Joined: Thu Feb 05, 2009 4:26 pm
Posts: 10
You could also just put them all in the same server declaration:

Code:
server {

            listen   80;
            server_name  www.foo.com foo.co.uk www.foo.co.uk;
            rewrite ^/(.*) http://foo.com/$1 permanent;

           }


Top
   
 Post subject:
PostPosted: Thu Feb 05, 2009 7:31 pm 
Offline
Newbie

Joined: Wed Nov 26, 2008 6:42 am
Posts: 2
Thanks guys. I'm liking the everything in the same declaration method. Implementing now.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group