Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
265 views
Welcome To Ask or Share your Answers For Others

1 Answer

first of all, you must replace http://blog.example.com/whatever_or_empty to http://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 temporary redirect(302(the default)) or permanent redirect(301).

So, using url rewriting to change the link http://blog.example.com/ to http://www.example.com/blog/ is useless.


Although, you can achieve this using Apache Module mod_proxy.

The Apache Proxy Modules has these:

  • mod_proxy: The core module deals with proxy infrastructure and configuration and managing a proxy request.
  • mod_proxy_http: This handles fetching documents with HTTP and HTTPS.
  • mod_proxy_ftp: This handles fetching documents with FTP.
  • mod_proxy_connect: This handles the CONNECT method for secure (SSL) tunneling.
  • mod_proxy_ajp: This handles the AJP protocol for Tomcat and similar backend servers.
  • mod_proxy_balancer implements clustering and load-balancing over multiple backends.
  • mod_cache, mod_disk_cache, mod_mem_cache: These deal with managing a document cache. To enable caching requires mod_cache and one or both of disk_cache and mem_cache.
  • mod_proxy_html: This rewrites HTML links into a proxy's address space.
  • mod_xml2enc: This supports internationalisation (i18n) on behalf of mod_proxy_html and other markup-filtering modules. space.
  • mod_headers: This modifies HTTP request and response headers.
  • mod_deflate: Negotiates compression with clients and backends.

You need at-least mod_proxy and mod_proxy_http modules enabled for the proxy to work:

you should have lines similar to these in your apache's conf file:

LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_module modules/mod_proxy.so

use this in your Virtualhost of http://www.example.com

ProxyPass /blog http://blog.example.com
ProxyPassReverse /blog http://blog.example.com
ProxyRequests On
ProxyVia On

<Proxy *>
Order allow,deny
Allow from all
</Proxy>

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:

options -indexes

Add a index to the folder blog.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...