Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am new to nginx, I have rewrite directives to redirect hostnames to other hostnames. I want to preserve the URI in the request to the redirect so for example http://www.johntate.org/blog goes to http://johntate.org/blog and so on.

At the moment I just have this...

server {
    listen 80;
    server_name www.johntate.org;
    rewrite / http://johntate.org/;
}

I want something more complicated that preserves the request and forwards it.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Adapted from the example on http://wiki.nginx.org/Pitfalls#Server_Name:

server {
    listen 80;
    server_name www.johntate.org;
    return $scheme://johntate.org$request_uri;
}

($scheme expands to http or https depending on connection type)

Have a look at the documentation at http://wiki.nginx.org/HttpRewriteModule before asking further questions on this.

share|improve this answer
    
Won't I need $request_uri on the end to preserve the specific request? –  John Tate Jul 14 '13 at 16:48
    
@JohnTate Oops, you are correct. I was not paying attention here. –  Lekensteyn Jul 14 '13 at 19:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.