View Full Version : Mapping a subdomain to a folder?
apfelKuh
09-10-2007, 12:48 PM
Hi,
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. www.mydomain.com and blog.mydomain.com.
I would like to have the blog available at www.mydomain.com/blog instead of it being on a subdomain.
How can I achieve this?
Regards
mistwang
09-11-2007, 10:57 AM
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.
ideaoforder
11-03-2008, 02:20 PM
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
11-03-2008, 03:52 PM
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.
ideaoforder
11-04-2008, 08:07 AM
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
11-04-2008, 08:33 AM
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/ (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
ideaoforder
11-04-2008, 08:47 AM
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
11-04-2008, 09:21 AM
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.