Orlo
Orlo

Reputation: 828

Nginx redirect all requests trying to reach a folder

How can I redirect all requests trying to reach a folder?

for example, I would like to redirect:

somedomain.com/folder/subfolder/index.html
somedomain.com/folder/subfolder2/something.html
somedomain.com/folder/subfolder3/somethingelse.html

to

somedomain2.com/index.html

what I've tried:

if ( $request_uri = "/folder/.*" ) {
  rewrite ^/(.*)$  http://domain2.com/embed.html    permanent;
}

Upvotes: 0

Views: 97

Answers (1)

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42799

you're just complicating things for no reason, no need to do an if condition, you should always try to avoid it as much as possible

location /folder { # this will match all subfolders and files
    return 301 http://domain2.com/embed.html;
}

Upvotes: 1

Related Questions