Migster
Migster

Reputation: 153

NGINX redirect everything except one directory and its subdirectories

How do I need to modify the code that everything redirects to another website except the directory "l"? Also, all like e.g. /l/test shouldn't redirect.

location / {
    return 301 https://www.example.com$request_uri;
}

location ~ /l {
    root /var/www;
    rewrite ^(.*)$ /index.php?l=$1 last;
}

Upvotes: 0

Views: 974

Answers (1)

Migster
Migster

Reputation: 153

With that configuration its works!

root /var/www/;

location / {
        return 301 https://www.example.com$request_uri;
    }

    location /l/ {
        rewrite ^/l/(.*)$ /index.php?p=$1 last;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #...
    }

Upvotes: 1

Related Questions