nginx rewrite查询字符串重写问题

请求格式

http://localhost/business/detail?itemId=123
重定向到:
http://localhost/business123

参考配置

user root;  
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  text/html;
    gzip  on;
    rewrite_log on;
    root /opt/demoapps;
    real_ip_header     X-Forwarded-For;
    server {
       listen 80;
       charset utf-8;
       default_type text/html;
       location / {
           index index.html index.htm index;
       }
       location ~* ^/business/detail {
            if ($args ~* "itemId=(\d+)") {
                set $w1 $1;
                set $args ''; 
                rewrite .* /business$w1 redirect;
            }
        }
     }
} 

说明

args参数问题,我们需要重置args 为空,这样规避影响

参考资料

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#rewrite

posted on 2021-09-09 21:32  荣锋亮  阅读(172)  评论(0编辑  收藏  举报

导航