how to exclude a location
October 23, 2009 06:27PM
Hello,

I wanted to find out if there is a way to exclude a certain location in order to do a rewrite i.e., location !~ /blah/ or something similar?
Re: how to exclude a location
October 28, 2009 06:43PM
Hello there,

Ok so if I understand you correctly, you need to do a rewrite for all URIs except ones starting with /blah/ ?

You can do that with the following rewrite, using negative lookahead, the example worked fine on my server:

[code]
rewrite ^(?!(/blah/))(.*)$ /dir_one/$2 break;
[/code]

This will rewrite any URI that is not in /blah/ to /dir_one/.

For example:
- file www.site.com/page.php will be rewritten to www.site.com/dir_one/page.php
- file www.site.com/dir_two/page.php will be rewritten to www.site.com/dir_one/dir_two/page.php
- file www.site.com/blah/page.php will remain unchanged

Hope this helped,
cheers
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 180
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready