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
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…