将一条路径下的所有内容重定向到另一个域 - nginx

时间:2016-03-23 11:32:18

标签: wordpress nginx

我在重写/重定向网址时遇到问题。

我有网站website.com/news ..其中/ news是所有文章。

我做了新的网站articles.website.com,我想重定向/ news下的所有链接重定向到articles.website.com。

所以在例子中:

website.com/news/awesome-article redirect / rewrite about articles.website.com/awesome-article ..是否可以使用nginx?谢谢。

我用过

     location ~ ^/news/(.*) {
  return 301 http://www.articles.website.com/$1;
}

但它仍然在articles.website.com/news/awesome-article上的新网址重定向..但是我想要它没有/新闻。

我想要重定向的网站vhost(website.com)

   server {
    listen   80; ## listen for ipv4; this line is default and implied

    root /var/www/vhosts/website.com;
    index index.html index.htm index.php;

    error_log /var/log/nginx/website.com.error.log;
    access_log /var/log/nginx/website.com.access.log;

    server_name dev.website.com website.com www.website.com;

    location / {
                try_files       $uri $uri/ /index.php?$args;
        }

#   location = /news {
  #return 301 http://articles.website.com$1;
#}

#   location = /news/ {
 # return 301 http://articles.website.com/$1;
#}

#   location = /news/wp-login.php {
 # return 301 http://articles.website.com/wp-login.php$1;
#}

      location ~ ^/news/(.*) {
return 301 http://articles.website.com/??$1;
}


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
    #   fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #   deny all;
    #}
}

1 个答案:

答案 0 :(得分:0)

抱歉打扰。我不知道为什么,但是nginx不想接受重定向。一夜之后,我仔细检查了那个规则,然后就开始了。