2016-08-13 11 views
1

私のnginx設定でrequest_uriを操作する方法を知りたいと思います。nginx - リダイレクト中にrequest_uriを操作する

uri domain1.com/post/{slug}のすべてのトラフィックをdomain2.com/blog/{slug}にリダイレクトしようとしています。

server { 
    listen 80; 
    server_name domain1.com; 
    return 301 $scheme://domain2.com/blog$request_url; 
} 

しかし、問題はdomain1.com/post/{slug}ではなくdomain2.com/blog/{slug}より、domain2.com/blog/post/{slug}にリダイレクトされます。

現在、私は次のように設定します。

ここからどのように進めることができますか?

答えて

0

returnステートメントではなくrewrite ... permanentステートメントを使用してください。

rewrite ^/post(.*)$ $scheme://domain2.com/blog$1 permanent; 
return 404; 

デフォルトの場合は、/postで始まらないURIのためにあるべきものは何でもしてreturn 404を交換してください。

詳細はthis documentを参照してください。

関連する問題