Mapping a subdomain to a folder?

Discussion in 'Install/Configuration' started by apfelKuh, Sep 10, 2007.

  1. apfelKuh

    apfelKuh New Member


    I didn't find a solution for this problem in existing threads, so here it goes:

    I have two rails virtual hosts running at e.g. and
    I would like to have the blog available at instead of it being on a subdomain.

    How can I achieve this?

  2. mistwang

    mistwang LiteSpeed Staff

    It requires configuration changes in both rails configuration and LSWS configuration, and some rails application simple won't work no matter what, like "typo". There are similar questions asked before, please search on the forum.
  3. ideaoforder

    ideaoforder Active Member

    +1 to subdomain mapping

    It seems like the question here is whether dispatch.lsapi can accept arguments. In a typical php setup (Ive never had to do this with Rails until now), you can pass arguments like so:

    RewriteRule ^(.*)$ index.php?arg=$1 [QSA,L]

    So is there a way to pass dispatch.lsapi a controller, action, or namespace?

    I understand that this is a complicated issue with many possible responses--but none of the standard Rails ways of handling this allow for a simple silent redirect. This is for a custom app, so I can manage the routes fine and am not worried about breaking anything. I seached the forums and couldn't find a question/answer that addressed this specifically.

    Thanks in advance for your time!
  4. mistwang

    mistwang LiteSpeed Staff

    You can use rewrite rule to rewrite any URL to /dispatch.lsapi?arg=$1
    Internally, LSWS use a 404 not found handler to route request to /dispatch.lsapi, if you explicitly rewrite URL to /dispatch.lsapi, it will override the default.
  5. ideaoforder

    ideaoforder Active Member

    Still Unsure

    Thank you for your speedy reply! However, I'm still not sure how I would redirect a subdomain to a controller/action/namespace. I understand URL rewriting in general, but am not sure what I need to put specifically. Perhaps an explanation of what I'd like will help:

    should go to

    In routes.rb I have

    map.namespace :mysubdomain do |mysubdomain|
    map.resources :mycontroller

    Thanks again!
  6. mistwang

    mistwang LiteSpeed Staff

    Are all subdomains handled by the same application? If yes, you need to do the following

    setup the rails vhost to serve and all its subdomains, will go to this vhost.

    then add a rewrite rule by extract the subdomain from HTTP_HOST, then rewrite the URL from /controller/action/id to /mysubdomain/controller/action/id
  7. ideaoforder

    ideaoforder Active Member

    Almost There

    Yep--all of the subdomains are pointing to the same domain and I have them pointed at the site. I can successfully do a 301 redirect, but my client would like the redirect to be silent. Just redirecting like so:

    RewriteCond %{HTTP_HOST} ^
    RewriteRule (.*)$1 [R=301,L]

    works fine, but shows the address change.

    So I need to know what RewriteRule, specifically will accomplish the above redirect silently.

    Something like:

    RewriteRule (.*) /mysubdomain/$1

    doesn't work. It just produces a 404.

    I assume I'd need something like:

    RewriteRule (.*) dispatch.lsapi?SOMETHING HERE=$1&NAMESPACE MAYBE=mysubdomain

    So I need a concrete example of the rewrite rule. Thanks again!
  8. mistwang

    mistwang LiteSpeed Staff

    try the following rewrite rule at vhost level

    RewriteCond %{HTTP_HOST} ^
    RewriteRule /(.*) /mysubdomain/$1 [L]

    rewrite rule in .htaccess may not work.

Share This Page