Nginx перенаправляет все запросы, пытаясь добраться до папки

1569
Orlo

Как я могу перенаправить все запросы, пытаясь добраться до папки?

например, я хотел бы перенаправить:

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

в

somedomain2.com/index.html 

что я пробовал:

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

1 ответ на вопрос

2
Bernard Rosset
server { server_name somedomain.com; location /folder/ { return 301 $scheme://somedomain2.com; } } server { server_name somedomain2.com; location / { #index index.html; # You could wish to add that, if index default value does not suits your needs } } 

That will issue a permanent redirect for any /folder/* request.

I took the liberty of mimicking the scheme being used with somedomain for somedomain2 with the $scheme variable.

I have not forced the /index.html URI in the redirect. You may wish to do it. I also relied on the default value of the index directive, which is maybe not right for you.

If you wished to handle the content from the other server transparently, you could use proxy_pass to proxy the request to it.

Похожие вопросы