问题描述
Nginx.原来的URL:http://www.域名.com/news/aaa.htmlhttp://www.域名.com/product/aaa/bbb/xxx.html需要把 /news/和/product/这2个目录下的网页重定向到以下URL:http://www.域名.com/old/news/aaa.htmlhttp://www.域名.com/old/product/aaa/bbb/xxx.html
问题解答
回答1:rewrite ^/(news|product)/(.*)$ /old/$1/$2 permanent last;
放server块里。随手写的,没测试。
回答2:server { server_name www.xxx.com xxx.com; if ($host != ’www.xxx.com’ ) {rewrite ^/(.*)$ http://www.xxx.com/$1 permanent; }}
关键在 permanent
子目录跳转:
location ~* ^/news/ { rewrite ^/news/(.*)$ http://www.xxx.com/old/news/$1 permanent;}回答3:
rewrite