【问题标题】:NGINX redirect everything except one directory and its subdirectoriesNGINX 重定向除一个目录及其子目录之外的所有内容
【发布时间】:2018-12-17 04:21:52
【问题描述】:

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

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

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

【问题讨论】:

  • 你打算如何处理你的 PHP 代码?您需要一些位置来将对 php 文件的请求传递给一些 HTTP 侦听后端或 fastcgi 守护进程。否则,您只会得到带有 nginx 响应的 index.php 的原始 php 内容。

标签: regex nginx redirect webserver


【解决方案1】:

使用该配置,它的工作原理!

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

【讨论】:

    猜你喜欢
    • 2014-10-16
    • 2016-03-18
    • 2012-07-14
    • 2013-10-30
    • 1970-01-01
    • 2013-09-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    相关资源
    最近更新 更多