繁体   English   中英

Nginx 从重定向中排除查询字符串 url

[英]Nginx Exclude a query string url from being redirected

我目前正在将我的根域重定向到一个子文件夹。 但是,我想排除用于 ajax 调用的查询字符串 url (www.example.com/?act=12)。 但是,我不确定如何在 nginx 中执行此操作。

这是我当前的 nginx 配置文件

server {
        listen          80;
        server_name     example.com;
        return 301      http://www.example.com$request_uri;

}

server {
        listen 80;
        server_name www.example.com;
        root /var/www/example.com/public;

        index index.php index.html;

        location = / {
                return 301 http://www.example.com/it/;
        }

        location / {
                proxy_pass http://localhost:8080;
                include /etc/nginx/proxy_params;
        }

        location ~* \.(js|css|jpg|jpeg|gif|png|svg|ico|pdf|html|htm)$ {
                expires 30d;
        }

        location ~ /\.ht {
        deny  all;
    }
}

任何帮助将不胜感激。

这可以通过使用邪恶的 if块来实现。

查询字符串参数显示为带有$arg_前缀的变量。 如果您只需要测试该act是否已设置,请尝试以下操作:

location = / {
    if ($arg_act) {
        rewrite ^ /my/ajax/call last;
    }
    return 301 http://www.example.com/it/;
}

如果您需要测试$arg_act的特定值, $arg_act使用=运算符。

有关详细信息,请参阅 此文档

暂无
暂无

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

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