1

全站换域名时利用nginx和javascript做简单友好的换域名跳转通知

 3 years ago
source link: https://blogread.cn/it/article/440?f=hot1
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

全站换域名时利用nginx和javascript做简单友好的换域名跳转通知

浏览:2590次  出处信息

在经过上一波的xiaonei.com转renren.com后,昨夜再次迎来新一波的kaixin->renren code的过程,期间有域名要求用新的域名,并且要老域名有跳转有提示,于是采用了下面的办法。

老域名是 old.com

新域名是 new.com

迁移挂维护的过程就略过了,直接说重点,

第一步,修改nginx.conf,删除原来old.com的定义,增加:

以下是代码片段:
server {
listen 80;
server_name old.com;
location / {
root   /old;
if (!-e $request_filename){
rewrite ^/(.*)?$ /index.html?t=$1 last;
}
}
}

第二步,在/old下放进一个index.html,代码如下:

以下是代码片段:
<div class=”all-error”>
<h1><span>old换名啦!</span>
<br>
原来old更名为new,请放心不会影响您的使用,新的地址为<a href=”http://new.com” id=”link”>new.c
om</a>谢谢您的支持!
</h1>
<p>
2秒之后自动跳转到新的地址…
</p>
</div>
<script type=”text/javascript”>
document.getElementById(”link”).href = location.href.replace(”old.com”,”new.com”);
setTimeout(function(){
location.href =  location.href.replace(”old.com”,”new.com”);
}, 2000)
</script>

第三步,关机,回家睡觉

建议继续学习:

QQ技术交流群:445447336,欢迎加入!
扫一扫订阅我的微信号:IT技术博客大学习

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK