alybadawy
alybadawy

Reputation: 529

nginx rewrite redirect for a folder

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?

Upvotes: 26

Views: 54760

Answers (2)

gsf
gsf

Reputation: 1818

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.

Upvotes: 54

oldmonk
oldmonk

Reputation: 739

Add below configuration into your nginx.conf

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

Upvotes: 7

Related Questions