Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have a Ruby on Rails application running at subdomain (e.g. on nginx with Passenger. Basically what I want it to do is keep application running at subdomain ( and redirect domain's root ( to another domain (e.g., but on webserver level (without another application running at domain root which would perform that redirect). I don't know how to do that (if it can be set up in nginx.conf, .htaccess, mod_rewrite etc. and how eventually), I'm new to this. Thanks for any idea.

EDIT: My nginx.conf

server {
    listen       80;
    root /server;    # because site on sub URI is located in /server/site 
    passenger_enabled on;
    passenger_base_uri /site; 
share|improve this question isn't a subdomain; it's a top-level directory. A subdomain would be – Kevin M Mar 6 '11 at 17:53
OK, I'll keep that in mind. Thanks. – Kreeki Mar 6 '11 at 18:01
up vote 1 down vote accepted

This should just be a 301 Redirect in .htaccess. In the domain root's directory, create or edit .htaccess and add the following line:

Redirect 301 /
share|improve this answer
Thanks. And how should I edit my nginx.conf file (posted in question above)? Now when I go to I get 403 Forbidden. – Kreeki Mar 6 '11 at 18:00
I've got it now. The file needed to be placed in /server directory. – Kreeki Mar 6 '11 at 18:37

Create a second document root using nginx(don't know how to do that; I don't use nginx). In's root, create a standard HTML file with the following in it the head section:

<meta http-equiv="refresh" content="0;url=">

The 0 tells the web browser how many seconds to wait before loading the new URL.

share|improve this answer
It's also the way. My problem now is how to configure nginx to "to be able to do anything" on domain's root. – Kreeki Mar 6 '11 at 18:06
Never ever do meta-redirects when you can use HTTP redirects. They are not supported by any plain HTTP tools, don't work reliably, incur a large overhead, and are just clunky. – Holger Just Mar 6 '11 at 21:25

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.