Nginx – Website running on subdomain, how to redirect root to other domain

nginxphusion-passenger

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; 
    }

Best Answer

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/