Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using nginx and want if user type to access the web, it will be redirected to, thanks.

share|improve this question

migrated from Feb 14 '11 at 1:44

This question came from our site for professional and enthusiast programmers.

IMO, it should be -> , www is redundant, its already the web. – Kent Fredric Feb 12 '11 at 15:47
I agree with Kent in that you should redirect from www to just – Jacob Feb 14 '11 at 2:07

I suggest that you take a look at the HttpRewriteModule and implement one that redirects all requests to to, preserving the original path.

share|improve this answer

What about

server {
    rewrite ^(.*)$1 permanent;

The permanent attribute makes nginx redirect by HTTP 301 instead of (I think) 302.

share|improve this answer
It can't because i have such domains already... – Bin Chen Feb 14 '11 at 2:45

Based on the rewrite rule from "Converting rewrite rules", you can use the following rewrite rule:

server {
    listen       80;
    rewrite   ^$request_uri?;
share|improve this answer

By far the simplest way to do this is at the DNS level and have the web server accept requests for both. No need to stuff around with rewriting.

share|improve this answer

Your Answer


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.