Mapping a subdomain to a folder?

mistwang

LiteSpeed Staff
#2
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
+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!
 

mistwang

LiteSpeed Staff
#4
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
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:

http://mysubdomain.example.com/controller/action/id

should go to http://example.com/mysubdomain/controller/action/id

In routes.rb I have

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

Thanks again!
 

mistwang

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

setup the rails vhost to serve example.com and all its subdomains, http://mysubdomain.example.com/... 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
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} ^mysubsomain.example.com
RewriteRule (.*) http://www.example.com/mysubdomain/$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!
 

mistwang

LiteSpeed Staff
#8
try the following rewrite rule at vhost level

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

rewrite rule in .htaccess may not work.
 
Top