刚刚在godaddy申请了新域名 www.iamle.com. 原有的www.iamle.cn域名决定废弃了.
我的这个博客跑在 Linux + mysql + nginx +php + WordPress 环境下. 为了更好的支持搜索引擎.绝对把www.iamle.cn全部的连接 301永久重定向到新域名 www.iamle.com下.
nginx配置中增加 www.iamle.com域名(下面的nginx配置未全部贴上.)
————————
listen 80;
server_name www.iamle.com iamle.com www.iamle.com iamle.cn;
————————
原来针对www.iamle.cn做的301规则
location / {
rewrite ^/post/([0-9]+)/$ /archives/$1.html permanent;
rewrite ^/post/([0-9]+)$ /archives/$1.html permanent;
#rewrite ^/html/y2009/([0-9]+).html$ /archives/$1.html permanent;
if ($host !~ “^www\.iamle\.cn$”){
rewrite ^(.*) http://www.iamle.cn$1 permanent;
}
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
——————————————————–
由于换域名后改为
server
{
listen 80;
server_name www.iamle.com iamle.com www.iamle.cn;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/wwekblog;
location ~ .*\.(php|php5)?$
{
root /home/wwwroot/wwekblog;
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location / {
rewrite ^/post/([0-9]+)/$ /archives/$1.html permanent;
rewrite ^/post/([0-9]+)$ /archives/$1.html permanent;
#rewrite ^/html/y2009/([0-9]+).html$ /archives/$1.html permanent;
if ($host !~ “^www\.iamle\.com$”){
rewrite ^(.*) https://www.iamle.com$1 permanent;
}
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
}
access_log off;
}
在linux命令行检查nginx配置是否正确.
[root@wwek sbin]# /usr/local/nginx/sbin/nginx -t
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
一个ok 一个successful表示配置文件没问题.
ps –e 列出nginx的进程id 这里我的是 2130
kill –HUP 2130 平滑重启nginx. 配置文件生效.
接着测试301是否转发成功.
测试 http://www.iamle.cn/archives/358.html
成功跳转 https://www.iamle.com/archives/358.html
测试 http://www.iamle.cn/post/358/
成功跳转 https://www.iamle.com/archives/358.html
不懂的朋友可以在本文下面留言,我可以帮你看看.^_^
Hi
Staying at my parents’ place, dying of boredom. Where can I have a good video chat?
Thank you on advance for your answer.
请问下这个规则怎么写
我想http://www.iamle.com/goto/http://www163.com/news/test.html或者http://www.iamle.com/goto/www163.com/news/test.html跳转到
http://www163.com/news/test.html
谢谢
旧域名的所有页面301永久重定向到新域名上对应的页面该怎么操作啊?我是在justhost买的虚拟主机。希望博主能够指点一下!
@xiaole, 你应该是Apache的吧 搜索Apache 301
博主啊 我现在也用的LNMP 但是我的是diz啊 一个域名下面是diz我想吧所有链接都顶到新的域名下面 这个域名不用了 你的这个是wp 不知道和diz有什么区别呢!! 真希望你能给我发个邮件啊 我给你每天点一次广告作为答谢!!! 🙂
把你的需求发这里我帮你写规则. 以
哈哈. 我的这个广告都没什么收入. 适当的帮点下就ok
呵呵 博主就是够意思啊!! 我先贴出来我的这个dz的server好了
server
{
listen 80;
server_name forum.bellepics.com bbs.xx-mm.com;
index index.html index.htm index.php;
root /home/shadowlong/bbs/;
rewrite ^/archiver/((fid|tid)-[\w\-]+\.html)$ /archiver/index.php?$1 last;
rewrite ^/forum-([0-9]+)-([0-9]+)\.html$ /forumdisplay.php?fid=$1&page=$2 last;
rewrite ^/thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /viewthread.php?tid=$1&extra=page\%3D$3&page=$2 last;
rewrite ^/space-(username|uid)-(.+)\.html$ /space.php?$1=$2 last;
rewrite ^/tag-(.+)\.html$ /tag.php?name=$1 last;
break;
location ~ .*\.(php|php5)?$
{
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ .*\.(htm|html|gif|jpg|jpeg|png|bmp|ico|css|js|txt|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
access_log off;
}
}
我想让bbs那个域名访问的时候全部跳转到 forum那个域名下面去!! 博主啊 麻烦你了啊!!!
在 root /home/shadowlong/bbs/; 行下增加
if ($host !~ “^forum\.bellepics\.com$”){
rewrite ^(.*) http://forum.bellepics.com$1 permanent;
}
我的vps装的nginx。如果是apache的确很简单。
😯 用的着这么麻烦吗?
直接
rewritecond %{HTTP_HOST} ^www.iamle.cn$
rewriterule . http://www.iamle.com/$1 [L]
wp根目录下的.htaccess文件里添加上面的代码就OK了。
何必这么麻烦呢?
我的vps装的nginx。如果是apache的确很简单。
nginx不支持 apache的 .htaccess。