VPS侦探论坛

 找回密码
 注册
查看: 3850|回复: 2

[Apache] 目录的重定向应该怎么写?

[复制链接]
发表于 2018-5-1 17:48:08 | 显示全部楼层 |阅读模式

有这样形式的URLwww.example.com/abc/1.html
www.example.com/bdc/3.html
www.example.com/utf/2.html
若干个,希望重定向到对应的
test.example.com/abc/1.html
test.example.com/bdc/3.html
test.example.com/utf/2.html

abc,bdc,utf这样的目录是已知固定数量的那几个。

不用root 映射,直接用nginx的rewrite 应该如何写?



  1. location ^~/(abc|bdc|utf)/(*.html) {

  2.    rewrite ^~/(abc|bdc|utf)/(*.html)  https://test.example.com/^~$1/$2  permanent;

  3. }
复制代码


这样写似乎不对,应该怎么写
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
发表于 2018-7-16 15:47:18 | 显示全部楼层


location /abc {
    rewrite ^/acb/(.*)$   http://test.example.com/abc/$1;
}
location /bdc {
    rewrite ^/dbc/(.*)$   http://test.example.com/dbc/$1;
}
location /utf {
    rewrite ^/uft/(.*)$   http://test.example.com/utf/$1;
}
Linux下Nginx+MySQL+PHP自动安装工具:https://lnmp.org
发表于 2018-7-16 15:49:47 | 显示全部楼层

if ( $request_uri ~* ^(/abc|bdc|uft)){
    rewrite ^/(abc|dbc|uft)/(.*)$  https://test.example.com/(abc|dbc|uft)/$1 last;
}

试试这样看行不
美国VPS推荐: 遨游主机LinodeLOCVPS主机云搬瓦工80VPSVultr美国VPS主机中国VPS推荐: 阿里云腾讯云。LNMP付费服务(代装/问题排查)QQ 503228080
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|VPS侦探 ( 鲁ICP备16040043号-1 )

GMT+8, 2024-4-29 19:28 , Processed in 0.026739 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表