換域名后導(dǎo)流到新域名
需要將之前用的www.a.com域名的流量全部跳轉(zhuǎn)到www.b.com
實現(xiàn)效果:比如訪問 www.a.com/123.html自動跳到www.b.com/123.html
我們用nginx實現(xiàn)
cd /etc/nginx/sites-available
vi mysite
增加rewrite命令
server {
listen 80;
server_name www.a.com;
rewrite ^/(.*)$ http://www.b.com/$1 permanent;
}
主域名跳轉(zhuǎn)到www域名
比如將主域名xxx.com 跳轉(zhuǎn)到www.xxx.com
cd /etc/nginx/sites-available
vi mysite
#主域名跳轉(zhuǎn)到www域名
server {
listen 80;
server_name xxx.com
rewrite ^/(.*)$ http://www.xxx.com/$1 permanent;
}
server {
listen 80;
server_name www.xxx.com;
#已省略余下通用配置內(nèi)容
}
主目錄跳轉(zhuǎn)于樟,子目錄不跳轉(zhuǎn)
a.com和www.a.com都跳到www.b.com
www.a.com/123不跳
server {
listen 80;
server_name www.a.us a.us;
#根目錄跳轉(zhuǎn)
location / {
rewrite .+ http://www.b.com/ permanent;
}
#非根目錄本地執(zhí)行
location ~* /.+ {
#已省略余下通用配置內(nèi)容
}
}