Rewrite help

Hi folks,

I need a rewrite rules like this

I have www.example.com, google.example.com, yahoo.example.com

I need to rewrite

Google.example.com à www.example.com/site/google

Yahoo.example.com à www.example.com/site/yahoo

How can I do that?

On Wed, May 5, 2010 at 3:09 PM, Glen L. [email protected]
wrote:

separate server block with rewrite on each blocks


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

Have a rewrite rule in the location / for each of the three site
configurations

Ray.

I tried

server {
listen 80;
server_name yahoo.example.com;

    rewrite ^.+ http://www.example.com/site/yahoo$uri last;

}

However it’s not rewrited. It’s being redirected to
http://www.example.com/site/yahoo

How about this?

server {
listen 80;
server_name yahoo.example.com;

   location / {
         rewrite ^(.*)$ http://www.example.com/site/yahoo$1 last;
   }

}

Ray.

On Wed, May 05, 2010 at 03:22:36PM +0700, Glen L. wrote:

I tried

server {
listen 80;
server_name yahoo.example.com;

    rewrite ^.+ http://www.example.com/site/yahoo$uri last;

}

However it’s not rewrited. It’s being redirected to http://www.example.com/site/yahoo

server {
server_name yahoo.example.com;
location / {
proxy_pass http://www.example.com/site/yahoo/;
}
}

server {
server_name google.example.com;
location / {
proxy_pass http://www.example.com/site/google/;
}
}

Google.example.com à www.example.com/site/google


nginx mailing list
[email protected]
nginx Info Page


Igor S.
http://sysoev.ru/en/

The results is same as before, it’s redirected to www

From: Ray [mailto:[email protected]]
Sent: 05 Mei 2010 15:33
To: [email protected]
Subject: Re: rewrite help

How about this?

server {
listen 80;
server_name http://yahoo.example.com/ yahoo.example.com;

   location / {

         rewrite ^(.*)$ http://www.example.com/site/yahoo$1 last;

   }

}

Ray.

On Wed, May 5, 2010 at 4:22 PM, Glen L. [email protected]
wrote:

I tried

server {
listen 80;
server_name yahoo.example.com;

   rewrite ^.+ http://www.example.com/site/yahoo$uri last;

}

However it’s not rewrited. It’s being redirected to
http://www.example.com/site/yahoo

In that case, Igor’s configs should work for you.

Ray.

On Wed, May 5, 2010 at 3:22 PM, Glen L. [email protected]
wrote:

well, if you actually want to access www.ex.com/site/yahoo without
rewriting you have to configure each server blocks manually (root,
etc).


O< ascii ribbon campaign - stop html mail - www.asciiribbon.org

On Wed, May 05, 2010 at 04:50:01PM +0700, Glen L. wrote:

Hi Igor,

It works already on index. But when i accessing
yahoo.example.com/test/article, it gives me error.

Where should it be proxied to ? To

http://www.example.com/site/yahoo/test/article

?

When i give proxy_pass http://www.example.com/site/yahoo.com$request_uri, it
giving me bad gateway

This is because nginx try dynamically resolve www.example.com without
resolver defined.

However, this way

    location / {
        proxy_pass  http://www.example.com/site/yahoo/;
    }

is better than

    location / {
        proxy_pass  http://www.example.com/site/yahoo/request_uri;
    }

server {
server_name yahoo.example.com;
}

I need to rewrite
separate server block with rewrite on each blocks


nginx mailing list
[email protected]
nginx Info Page


nginx mailing list
[email protected]
nginx Info Page


Igor S.
http://sysoev.ru/en/

Hi Igor,

It works already on index. But when i accessing
yahoo.example.com/test/article, it gives me error.

When i give proxy_pass
http://www.example.com/site/yahoo.com$request_uri, it
giving me bad gateway

Yes it should be rewrite to
http://www.example.com/site/yahoo/test/article

Is there any way to do this?

Best Regards,

Glen L.