1

wordpress を実行するサイト example.com があります。このブログをサブドメイン blog.example.com に移動したいのですが、次のことも必要です。

example.com --> static page (not wordpress)

blog.example.com --> new address to the blog
blog.example.com/foo --> handled by wordpress

example.com/foo --> permanent redirect to blog.example.com/foo

だから私はこの次の構成を試しました:

    server {
            server_name example.com;

            location = / {
                    root /home/path/to/site;
            }

            location / {
                    rewrite ^(.+) http://blog.example.com$request_uri? permanent;
            }
    }

この場合、リダイレクトは完全に機能しています。残念ながら、example.com は blog.example.com にもリダイレクトされます。

4

2 に答える 2

2

リダイレクトする理由は、example.com のインデックス ファイルを読み込もうとするときに、/index.html への内部リダイレクトを実行するためです。これは、書き換え場所によって処理されます。これを回避するには、try_files を使用できます。

server {
  server_name example.com;

  root /home/path/to/site;

  location = / {
    # Change /index.html to whatever your static filename is
    try_files /index.html =404;
  }

  location / {
    return 301 http://blog.example.com$request_uri;
  }
}
于 2012-07-12T23:07:38.547 に答える
1

server2 つのドメインのルートが異なるディレクトリを指している限り、次のような2 つのディレクティブが必要になります。

server {
        # this is the static site
        server_name example.com;

        location = / {
                root /home/path/to/static/page;
        }

        location /foo {
                return 301 http://blog.example.com$request_uri;
        }
}

server {
        # this is the WP site
        server_name blog.example.com;

        location = / {
                root /home/path/to/new_blog;
        }

        .... some other WP redirects .....
}
于 2012-07-12T22:44:35.613 に答える