nginx redirect all directories except one nginx redirect all directories except one nginx nginx

nginx redirect all directories except one


location / {    rewrite ^/(.*)$ http://www.google.com/search?q=$1 permanent;}location /blog {      root   html;      index index.php;      try_files $uri $uri/ /blog/index.php;}


This situation can also be handled using only regex. Though this is a very old question and it has been marked answered, I'm adding another solution.

If you use multiple loop forwards using reverse proxy this is the easiest way without having to add a separate location block for every directory.

root html;index index.php;location / { #Match all dir      try_files $uri $uri/ $uri/index.php;}location ~ /(?!blog|item2)(.*)$ { #Match all dir except those dir items skipped      rewrite ^/(.*) http://www.google.com/search?q=$1 permanent;}