0

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; 
    }
Kreeki
  • 103
  • 4
  • mydomain.com/site isn't a subdomain; it's a top-level directory. A subdomain would be site.mydomain.com – Kevin M Mar 06 '11 at 17:53

2 Answers2

1

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/
ajdecon
  • 1,301
  • 4
  • 14
  • 21
  • 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 06 '11 at 18:00
  • I've got it now. The file needed to be placed in /server directory. – Kreeki Mar 06 '11 at 18:37
-1

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.

Kevin M
  • 2,312
  • 1
  • 16
  • 21
  • 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 06 '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 06 '11 at 21:25