I want to have 2 Ruby on Rails applications on a domain.
The first one is running at example.com
; I have done that with .htaccess (with RewriteRule to example.com:12001
)
I want the other one to be in a subdomain, like blog.example.com
. So I created a subdomain, and in the file .htaccess I redirect to example.com:12002
.
Everything is working fine, but if I go to address example.com/blog
, I am not redirected, and I see in browser the contents of blog folder in public_html:
Index of /blog
Parent Directory
I would like to go to the second application(blog.example.com
) when the url is example.com/blog
. How could I do that?
the solution depends on how your hosting provider implements multi-subdomain mapping. Some offer a control panel so that you can register your subdomains and point each to a separate subdirectory in your file space. Some will just map
*.yourdomain.zzz
to the document root foryourdomain.zzz
, and from your description, this is what is happening for you. In this case you need to decode the HTTP_HOST variable and route on that. But you also need to stop your rewrite rule looping so thatsub1.yourdomain.zzz
doesn't get mapped to yourDocRoot/sub1/sub1/sub1...`If you wanted to process sub1 and sub2 subdomains, then you would do this with a rule in you top level like this:
Search for [.htaccess] HTTP_HOST to see lots of variants of this.
first of all, you must replace
http://blog.example.com/whatever_or_empty
tohttp://www.example.com/blog/whatever_or_empty
in your HTML hrefs.blog.example.com
although a sub domain, is a different URL. i.e. when a RewriteRule does a rewrite to another URL an external redirect will occur. This will reflect in the browser. Be a temporaryredirect(302(the default))
orpermanent redirect(301)
.So, using url rewriting to change the link
http://blog.example.com/
tohttp://www.example.com/blog/
is useless.Although, you can achieve this using Apache Module mod_proxy.
The Apache Proxy Modules has these:
You need at-least
mod_proxy
andmod_proxy_http
modules enabled for the proxy to work:you should have lines similar to these in your apache's
conf
file:use this in your
Virtualhost
ofhttp://www.example.com
Definitions:
You can also use a cache with
mod_cache
:mod_cache
.For more on caching, refer here: mod_cache Apache Docs.
Also disable index views indexes by setting this:
Add a
index
to the folderblog
.