nginx, redirect requests similar to /page/123_index.json to /page/index.json. How to configure it?
天蓬老师
天蓬老师 2017-05-16 17:10:33
0
2
707
location ~ ^/pages/\d+_index.json{
    proxy_pass /pages/index.json;
}

I tried it but it didn’t work
I’m not familiar with nginx configuration, please ask for advice.

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(2)
PHPzhong

You can use rewrite to rewrite your request path

    location / {
        rewrite ^/pages/\d+_index\.json /pages/index.json break;
        proxy_pass http://127.0.0.1:8080;
    }
    # 测试下 会返回重写后的 url /pages/index.json
    location = /pages/index.json {
        return 200 $request_uri;
    }
阿神

I found two solutions
rewrite:

location ~ ^/pages/{
     rewrite ^/pages/(\d+)/\d+_index.json   http://$host/pages//index.json break;
}

proxy_pass

location ~ ^/pages/(\d+)/\d+_index.json$ {
    proxy_pass http://$host/pages//index.json;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!