Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Sun Aug 08, 2010 1:40 pm 
Offline
Senior Newbie

Joined: Sat Mar 27, 2010 12:32 am
Posts: 6
Hi,

I have a question about rewriting non WWW urls to WWW urls...
I have acomplished this with:

Code:
server {
   listen        80;
   server_name   mydomain.com;
   rewrite ^(.*) http://www.mydomain.com$1 permanent;
   }


It works BUT what is the difference with this syntax:

Code:
server {
   listen        80;
   server_name   mydomain.com;
   rewrite ^/(.*) http://www.mydomain.com/$1 permanent;
   }


On the second example there are two slash symbols / added inside the syntax and it seems the second syntax gives the same result.

But which one is correct to use???


The first syntax without the slash symbols or the second syntax with the slash symbols included? Is there any difference in usability or in the produced result? It looks they work the same but maybe there is something that i dont see.


Thanks for any help

George


Top
   
 Post subject:
PostPosted: Sun Aug 08, 2010 3:30 pm 
Offline
Junior Member
User avatar

Joined: Thu Apr 29, 2010 3:32 pm
Posts: 44
Website: http://devjonfos.net
Location: Oregon
sry, mis-read post - deleted


Top
   
 Post subject:
PostPosted: Sun Aug 08, 2010 4:06 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
They're both fine,

the first one means take whatever is after mydomain.com and append it to www.mydomain.com then redirect.

The second one means take whatever is after the / after mydomain.com and append it to www.mydomain.com/ and redirect.

However, the second one will not redirect "http://mydomain.com" since it doesn't end with a slash.


Top
   
 Post subject: nginx rewrites
PostPosted: Mon Aug 16, 2010 6:29 am 
Offline
Senior Newbie

Joined: Thu Mar 11, 2010 10:42 am
Posts: 15
ICQ: 33922655
Location: Ireland
Here's some other options...

It may be more correct to do:

Code:
server {
   listen        80;
   server_name   .mydomain.com;
   if ($host != 'www.mydomain.com' ) {
      rewrite ^(.*) http://www.mydomain.com$1 permanent;
   }
}


Or an example if found to achieve the same:

Code:
server {
  listen          80;
  server_name     domain.com *.domain.com;
  rewrite ^       http://www.domain.com$request_uri permanent;
 }
server {
  listen          80;
  server_name     www.domain.com;
  index           index.html;
  root            /home/domain.com
}

_________________
Linode 512 @ cbr250.com


Top
   
 Post subject: Re: nginx rewrites
PostPosted: Tue Aug 17, 2010 10:35 am 
Offline
Senior Member

Joined: Tue Feb 19, 2008 10:55 am
Posts: 164
RoryH wrote:
Here's some other options...

It may be more correct to do:


Or an example if found to achieve the same:

Code:
server {
  listen          80;
  server_name     domain.com;
  rewrite ^       http://www.domain.com$request_uri permanent;
 }
server {
  listen          80;
  server_name     www.domain.com;
  index           index.html;
  root            /home/domain.com
}


I like that, no regex, immeasurably quicker.


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


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
cron
RSS

Powered by phpBB® Forum Software © phpBB Group