NGINX 重定向除一个目录及其子目录之外的所有内容

NGINX redirect everything except one directory and its subdirectories

除了目录"l"之外的所有内容都重定向到另一个网站的代码,我需要如何修改?此外,都像例如/l/test 不应重定向。

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

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

有了这个配置就可以了!

root /var/www/;

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

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