LNMP环境实现301重定向的方法

发表时间:2012-06-12 8:44 | 分类:Linux | 浏览:3,299 次

原来我的网站重定向只是在.htaccess文件里这么写:

RewriteEngine on
RewriteCond %{http_host} ^sijitao.net [NC]
RewriteRule ^(.*)$ https://zhangnq.com/$1 [L,R=301]

因为自己用的linux系统的vps主机,而且安装的是lnmp,所以找到如下新的方法试试:
打开/usr/local/nginx/conf/vhost下相应的.conf文件,在代码的最后面加上如下代码:
server {
server_name sijitao.net;
rewrite ^(.*) https://zhangnq.com/$1 permanent;
}

最后得到的完整代码如下所示:
server
{
listen       80;
server_name blog.nbhao.org;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/blog.nbhao.org;   include none.conf;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fcgi.conf;
}   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires      30d;
}   location ~ .*\.(js|css)?$
{
expires      12h;
}   access_log off;
}
server {
server_name sijitao.net;
rewrite ^(.*) https://zhangnq.com/$1 permanent;
}

修改保存后记得重启lnmp,/root/lnmp restart  。这样用户打开sijitao.net时候也会转到blog.nbhao.org去了。不过sijitao.net虽然用了301重定向,但还是要做A记录解析的。

本文标签:, , ,

本文链接:https://www.sijitao.net/878.html

欢迎您在本博客中留下评论,如需转载原创文章请注明出处,谢谢!

现在只有1个回复
Comment (0)
Trackbacks (1)
一键脚本 博客历程 留言联系 文章归档 网站地图 谷歌地图
Copyright © 2010-2024 章郎虫博客 All Rights Reserved.