rewrite rules issue

Francis Daly francis at daoine.org
Sun Apr 19 11:04:38 UTC 2015


On Sun, Apr 19, 2015 at 04:06:55AM -0400, nicocolt wrote:

Hi there,

> Here is the directory path:
> 
> /var/www/domain.fr/web/subdomain/directory
> 
> my nginx conf is:
> 
> root /var/www/domain.fr/web
> 
> if ($http_host = "subdomain.domain.fr") {
>             rewrite ^(?!/\b(subdomain|stats|error)\b)/(.*)$ /subdomain/$2
> last;
> }
> 
> The if statement is before all of location directives.
> 
> After purging my cache browser, this is what I get:
> 
> when i reach http://subdomain.domain.fr/directory i'm redirected to
> http://subdomain.domain.fr/subdomain/directory (this is not what i want, i
> want http://subdomain.domain.fr/directory)

Ok, this makes a bit more sense now: your request actually might use
the configuration shown.

Are you sure that you have copy-pasted exactly the response? I would have
expected a redirect to http://subdomain.domain.fr/subdomain/directory/
-- but the actual redirect comes from the configuration that you have
not yet shown.

Your rewrite says that you *do* want the request to be handled like
http://subdomain.domain.fr/subdomain/directory, so I'm still not sure
what the actual full end intention is.

It does look to me like

 server_name subdomain.domain.fr;
 root /var/www/domain.fr/web/subdomain;

is probably what you really want, but I guess there is some reason why
you don't just use that?

Good luck with it,

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list