nginx permanent move not registered by the browser

We had a "beta" site set up under http://beta.domain.com, while http://www.domain.com contained a launch page. We now got rid of the launch page and moved the site over to the actual domain. I set up a permanent redirect in nginx to deal with this, but it somehow is not redirecting properly.

server {     server_name beta.domain.com;      rewrite ^/(.*) http://www.domain.com/$1 permanent;  } 

When I test it out using curl, it seems to work as expected.

$ curl -v beta.domain.com/page > GET /page HTTP/1.1 > User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5 > Host: beta.domain.com > Accept: */* >  < HTTP/1.1 301 Moved Permanently < Server: nginx/1.2.1 < Date: Tue, 16 Jul 2013 20:37:03 GMT < Content-Type: text/html < Content-Length: 184 < Connection: keep-alive < Location: http://www.domain.com/page <  <html> <head><title>301 Moved Permanently</title></head> <body bgcolor="white"> <center><h1>301 Moved Permanently</h1></center> <hr><center>nginx/1.2.1</center> </body> </html> 

However, when I go to http://beta.domain.com/page in Firefox, I get redirected to http://www.domain.com instead of http://www.domain.com/page. If I go directly to http://www.domain.com/page in Firefox, that works as expected.

I want to fix this with proper permanent redirect for SEO, but can't figure out the cause of this issue. We are using a Python/Django deployment running on Apache/ModWSGI, with nginx as the frontend server.

Thanks!

Replay

Try using return instead.

server {
    listen [::]:80;
    server_name beta.example.com;
    return 301 $scheme://www.example.com$request_uri$is_args$args;
}

Comparing with some rewrites on my server you may have a some unneeded slashes

try rewrite ^(.*) scheme://www.domain.com$1 permanent;

Category: nginx Time: 2013-07-16 Views: 3

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.250 (s). 12 q(s)