将所有路径重定向到另一个域-Nginx

谵妄

我的重写/重定向网址有问题。

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

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

因此,在示例中:

可以在nginx上对website.com/news/awesome-article进行重定向/重写在articles.website.com/awesome-article上吗?谢谢你。

我用了

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

但是它仍然在articles.website.com/news/awesome-article ..上的新URL重定向上,但是我希望在没有/ news的情况下使用它。

我要重定向的网站的虚拟主机(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;
    #}
}
谵妄

很抱歉打扰。我不知道为什么,但是nginx不想接受该重定向。晚上过后,我仔细检查了该规则,它很正常。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Nginx将一个子目录的所有内容重定向到另一个子目录

Nginx URL屏蔽到另一个域

nginx:将所有内容从http重定向到https,除了一个url模式

Gitlab Omnibus:如何将所有请求重定向到另一个域

Nginx:重定向除一个以外的所有内容

Nginx将http重定向到https并通过一个重定向删除尾部斜杠

nginx将所有域重定向到另一个端口,但为管理应用程序保留一个域

从特定路径到另一个特定路径的nginx proxy_pass引发错误

NGINX将所有与参数匹配的URL重定向到子域

Apache动态将一个域重定向到另一个域

如何使用htaccess在斜杠后使用参数将所有子域重定向到另一个?

htaccess将所有内容从域/文件夹重定向到另一个域

Nginx 301从页面重定向到另一个

如何将Nginx中的根域单独重定向到另一个URL

Nginx将所有域重定向到同一服务器块

无法将https站点重定向到另一个URL-Nginx服务器块

NGINX将所有重定向到https(一个目录除外)

使用NGINX将子域重定向到Docker容器

nginx重定向(或代理)到本地主机上的另一个应用程序

Nginx位置代理将首页传递到一个地方,所有其他路线传递到另一个地方

使用Nginx将'/ blog'重定向到另一个实例上托管的Wordpress网站

如何将nginx请求重定向到不同的路径

nginx 将 301 所有页面重定向到另一个域/主页添加查询字符串

.htaccess 将一个域重定向到另一个域

使用授权标头将 nginx 重定向到另一个域

nginx 重定向到一个错误的域

配置 Nginx 将所有 404 错误重定向到默认的 nginx 错误页面

将 2 个 url (%20) 重定向到 nginx 中的一个

如何仅将域重定向到另一个域而不是 nginx 中的子域和文件夹