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

I have a Ruby on Rails application running at subdomain (e.g. mydomain.com/site) on nginx with Passenger. Basically what I want it to do is keep application running at subdomain (mydomain.com/site) and redirect domain's root (mydomain.com) to another domain (e.g. myseconddomain.com), 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;
    server_name  www.mydomain.com;
    root /server;    # because site on sub URI is located in /server/site 
    passenger_enabled on;
    passenger_base_uri /site; 
    }
share|improve this question
    
mydomain.com/site isn't a subdomain; it's a top-level directory. A subdomain would be site.mydomain.com –  Kevin M Mar 6 '11 at 17:53
    
OK, I'll keep that in mind. Thanks. –  Kreeki Mar 6 '11 at 18:01
add comment

2 Answers

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 / http://www.myseconddomain.com/
share|improve this answer
    
Thanks. And how should I edit my nginx.conf file (posted in question above)? Now when I go to www.mydomain.com 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
add comment

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

<meta http-equiv="refresh" content="0;url=http://myseconddomain.com/">

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
add comment

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.