如何重定向尝试访问文件夹的所有请求?
例如,我想重定向:
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)
你只是无缘无故地复杂化,不需要做if条件,你应该总是尝试avoid it as much as possible
location /folder { # this will match all subfolders and files
return 301 http://domain2.com/embed.html;
}