开发者社区> 问答> 正文

linuxnginx服务器域名怎么做301重定向

装的是Discuz x3的程序,我的域名被我解析了三个:
www.txahz.com 用作门户
bbs.txahz.com 用作论坛
txahz.com
网站是弄好了,就是txahz.com 的这个域名也能打开,默认是论坛,但是用站长检查工具检查和论坛的数据都不一样。 所以我想把第三个域名301到www开头的门户(也是为了集中权重)。

这是bbs论坛的


这是主域名


这是www门户的


我没设置,默认解析后的这个域名是301到论坛


通过网上的教程,我在AMH里修改了Rewrite规则
在最下面的加上:
if ($host != 'www.txahz.com' ) {
rewrite ^/(.*)$ http://www.txahz.com/$1 permanent;
}
这样做txahz.com是可以跳转到 www.txahz.com了,但是bbs开头的也跳转到这个了。。。。

所以请路过的指点点这个规则怎么写好?还是要怎么操作?

展开
收起
chenhao0121 2013-09-03 15:32:49 19936 0
8 条回答
写回答
取消 提交回答
  • Relinuxnginx服务器域名怎么做301重定向
    我也想用云主机,又怕数据不好迁移。
    2014-05-23 12:02:38
    赞同 展开评论 打赏
  • 回2楼服务器之家的帖子
    请问用的帝国程序,怎么做301重定向。


    我网上查找过,说是修改这个文件—     /alidata/server/nginx-1.2.5/conf  


    打开这个文件是这样的:
    -----------------------------------------

    server {
            listen       80;
            server_name  localhost;
        index index.html index.htm index.php;
        root /alidata/www/phpwind;
        location ~ .*\.(php|php5)?$
        {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires 1h;
        }
        
        #伪静态规则
        include /alidata/server/nginx/conf/rewrite/phpwind.conf;
        access_log  /alidata/log/nginx/access/phpwind.log;


    }


    --------------------------------------------------------


    在论坛问过,说是加上这段代码:
    -----------------------------------------------------

    server {
      server_name www.domain.com;
      return 301 $scheme://domain.com$request_uri;
    }
    server {
      server_name domain.com;
      [...]
    }


    我想问问如果是正确的,那么代码加在哪个位置。


    还有这个文件是做什么的,是不是不同的程序改的文件不同啊,我网上找方法时,有的说是改这个文件—/alidata/server/nginx-1.2.5/conf/vhosts
    里面代码如下:



    server {
            listen       80;
            server_name  localhost;
        index index.html index.htm index.php;
        root /alidata/www/phpwind;
        location ~ .*\.(php|php5)?$
        {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }
        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires 30d;
        }
        location ~ .*\.(js|css)?$
        {
            expires 1h;
        }
        
        #伪静态规则
        include /alidata/server/nginx/conf/rewrite/phpwind.conf;
        access_log  /alidata/log/nginx/access/phpwind.log;


    }
    ------------------------------------------------------


    最后问一个问题就是,nginx 里   404页面是怎么设置的,哪里改啊。

    -------------------------

    回2楼服务器之家的帖子
    请问用的帝国程序,怎么做301重定向。


    我网上查找过,说是修改这个文件—     /alidata/server/nginx-1.2.5/conf  


    打开这个文件是这样的:
    -----------------------------------------

    server {
            listen       80;
            server_name  localhost;
            index index.html index.htm index.php;
            root /alidata/www/phpwind;
            location ~ .*\.(php|php5)?$
            {
                    #fastcgi_pass  unix:/tmp/php-cgi.sock;
                    fastcgi_pass  127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi.conf;
            }
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                    expires 30d;
            }
            location ~ .*\.(js|css)?$
            {
                    expires 1h;
            }
            
            #伪静态规则
            include /alidata/server/nginx/conf/rewrite/phpwind.conf;
            access_log  /alidata/log/nginx/access/phpwind.log;


    }


    --------------------------------------------------------


    在论坛问过,说是加上这段代码:
    -----------------------------------------------------

    server {
      server_name www.domain.com;
      return 301 $scheme://domain.com$request_uri;
    }
    server {
      server_name domain.com;
      [...]
    }


    我想问问如果是正确的,那么代码加在哪个位置。


    还有这个文件是做什么的,是不是不同的程序改的文件不同啊,我网上找方法时,有的说是改这个文件—/alidata/server/nginx-1.2.5/conf/vhosts
    里面代码如下:



    server {
            listen       80;
            server_name  localhost;
            index index.html index.htm index.php;
            root /alidata/www/phpwind;
            location ~ .*\.(php|php5)?$
            {
                    #fastcgi_pass  unix:/tmp/php-cgi.sock;
                    fastcgi_pass  127.0.0.1:9000;
                    fastcgi_index index.php;
                    include fastcgi.conf;
            }
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                    expires 30d;
            }
            location ~ .*\.(js|css)?$
            {
                    expires 1h;
            }
            
            #伪静态规则
            include /alidata/server/nginx/conf/rewrite/phpwind.conf;
            access_log  /alidata/log/nginx/access/phpwind.log;


    }
    ------------------------------------------------------


    最后问一个问题就是,nginx 里   404页面是怎么设置的,哪里改啊。


    2014-04-11 17:17:32
    赞同 展开评论 打赏
  • 楼上方法没错啊
    2014-04-02 09:59:27
    赞同 展开评论 打赏
  • Relinuxnginx服务器域名怎么做301重定向
    但是这里又出现问题了呢!!!
    如果这样子冲定向了,本来是http://bbs.xxx.com里面的文章如http://bbs.xxx.com/thread-1-1-1.html;如果此网址没有bbs变成http://xxx.com/thread-1-1-1.html的话就被重定向为http://www.xxx.com//thread-1-1-1.html的了,其实我们是不想把bbs的文章指向到www下面的,但实际上它这样子就直接把bbs里面的文章指向到www下面了!
    这样子怎么破呢?
    2014-03-11 17:27:24
    赞同 展开评论 打赏
  • 用301重定向 即可解决  
    2013-09-04 09:35:07
    赞同 展开评论 打赏
  • 回 5楼(chenhao0121) 的帖子
    那你错了,也一样的会有的
    2013-09-03 18:43:04
    赞同 展开评论 打赏
  • 代码改成
    if ($host = 'txahz.com' ) {
    rewrite ^/(.*)$ http://www.txahz.com/$1 permanent;
    }

    -------------------------

    301的代码要放在伪静态规则的上面
    否则匹配成功伪静态的规则后就不会匹配后面301的规则
    比如
    xxx.com会301到www.xxx.com

    http://xxx.com/thread-1-1-1.html则不会301到http://www.xxx.com/thread-1-1-1.html

    -------------------------

    回 9楼(chenhao0121) 的帖子
    没问题
    2013-09-03 17:08:14
    赞同 展开评论 打赏
  • Relinuxnginx服务器域名怎么做301重定向
    对了,www和bbs都指向一个程序,门户和论坛没有分开

    -------------------------

    Relinuxnginx服务器域名怎么做301重定向

    原来是我自己的疏忽,多了个.com

    -------------------------

    回3楼mayle的帖子
    谢谢,我知道同一个程序设置门户和论坛,然后门户调用论坛的帖子会导致重复收录,但我是门户和论坛分开运行的。

    我门户是用文章,不是直接调用论坛的,所以不会有普遍的那种现象

    -------------------------

    回8楼服务器之家的帖子
    谢谢你的提醒,这样对吗,放到所有代码的最上面了
    2013-09-03 15:35:01
    赞同 展开评论 打赏
滑动查看更多
问答排行榜
最热
最新

相关电子书

更多
创业公司的域名想象 立即下载
“域”见更美好的未来——域名筑梦互联网+ 立即下载
“域”感——《域名投资从入门到精通》 立即下载