nginx rewrite redirect for a folder

2019-03-18 19:04发布

问题:

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?

回答1:

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.



回答2:

Add below configuration into your nginx.conf

rewrite ^/(images.*) /assets/$1 permanent;