rewrite rule needed for subdomains

Igor Sysoev is at rambler-co.ru
Tue Nov 3 23:56:06 MSK 2009


On Tue, Nov 03, 2009 at 09:03:22PM +0100, Mike Smith wrote:

> We have a lot of magento stores that work like
> 
> store1.domain.com
> store2.domain.com
> 
> so a user can go into store1.domain.com/products/ and the url will stay
> there
> 
> We do this in apache like
> 
>     RewriteCond %{HTTP_HOST} !^(host)\.domain\.com [NC]
>     RewriteCond %{HTTP_HOST} !^(www)\.domain\.com [NC]
>     RewriteRule ^(.*) /magento/$1 [L]
> 
> 
> We also have a dns catchall that will send all *.domain.com to a default
> apache vhost. I'm slamming my head against the wall to get it working in
> nginx to keep the hostname the same but behind the scenes rewrite the
> domain for magento to parse.
> 
> Here is what I have but it just keeps appending /magento/magento/magento
> to the end till it kills the loop
> 
>         if ($http_host !~ "^www.domain\.com$") {
>             rewrite ^.+ http://$http_host/magento/$uri last;
>             break;
>         }

    server {
        # a catchall server for "listen 80",
        # since it's "default" server for "listen 80"

        listen 80 default;
        server_name  store1.domain.com;

        location / {
            rewrite ^   http://$host/magento/$request_uri? last;
        }

        location /magento/ {
            ...
        }
    }

    server {
        listen 80;
        server_name  www.domain.com  host.domain.com;
        ...
    }


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list