nginx rewrite redirect for a folder

2019-03-18 19:07发布

all...

I am trying to do something in nginx to redirect all calls for files in

/images/

to become in:

/assets/images/

can someone help me with the rewrite rule? giving a 301 moved permanently status?

2条回答
Explosion°爆炸
2楼-- · 2019-03-18 19:52

Add below configuration into your nginx.conf

rewrite ^/(images.*) /assets/$1 permanent;
查看更多
虎瘦雄心在
3楼-- · 2019-03-18 20:04

Here's the preferred way to do this with newer versions of Nginx:

location ~ ^/images/(.*) {
    return 301 /assets/images/$1;
}

See https://www.nginx.com/blog/creating-nginx-rewrite-rules/ for more info.

查看更多
登录 后发表回答