简体   繁体   English

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

[英]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"? 我该如何修改所有重定向到除“ l”目录之外的其他网站的代码? Also, all like eg /l/test shouldn't redirect. 另外,所有类似/ l / test之类的都不应重定向。

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

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

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;
        #...
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM