我一直有问题,将一个旧的子文件夹完全重定向到一个新的子文件夹。我需要/old和/old/分别转到/new和/new/
我还需要在/ old /blah/blah 2/ to / new /blah/blah 2/之后跟随任何参数,因此,无论什么叫新的,基本上都是用新的替换旧的。下面是我能得到的最接近的。
location /account/ {
rewrite ^/account/(.*)$ https://$server_name/portal/$1 permanent;
}实际URL示例:
www.domain.com/account/index.php?loend=true&cmd=callback&module=8需要是www.domain.com/portal/index.php?loend=true&cmd=callback&module=8
谢谢
发布于 2014-07-29 16:50:11
您能尝试重写^/.*/()$ /portal/$1;吗?不需要把它放在地点/帐户/{.}-纪尧姆7月24日19:00
仅使用:重写^/account/(.*)$ /portal/$1;没有指定位置就解决了所有问题
发布于 2014-07-24 15:53:06
它应该能用,但你在里面漏掉了$的签名。这里更正了一个位代码
rewrite ^/account/(.*)$ https://$server_name/portal$1 redirect;或
rewrite ^/account/(.*)$ https://$server_name/portal$1 last;或
rewrite ^/account/(.*)$ https://$server_name/portal$1;而不是重新加载nginx的配置
service nginx reload这是来源网站。
https://www.digitalocean.com/community/questions/301-redirect-nginx
发布于 2014-07-24 22:30:09
由于这看起来更像是重定向而不是重写,所以我将使用返回。
location ^~ /account(.*) {
return 301 https://$server_name/portal$1$is_args$query_string;
}$is_args$query_string将添加任何查询字符串,就像您在其中一个注释loend=true&cmd=callback&module=8中提到的那样,还需要注意,如果$server_name是server_name的同名,您可以用$http_host替换它,并保持它的动态。
https://stackoverflow.com/questions/24932244
复制相似问题