java
html
c
xml
python
mysql
linux
android
visual-studio
eclipse
html5
json
algorithm
facebook
cocoa
apache
php5
asp
api
If you're using apache, you need to match the host part of the url (e.g. blog.test.com) in a RewriteCond:
RewriteCond %{HTTP_HOST} ^blog.test.com$ [NC] RewriteRule ^(.*)$ http://www.test.com/blog/$1 [R=301,L]
first of all, you must replace http://blog.test.com/whatever_or_empty to http://www.test.com/blog/whatever_or_empty in your HTML hrefs.
http://blog.test.com/whatever_or_empty
http://www.test.com/blog/whatever_or_empty
blog.test.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).
blog.test.com
redirect(302(the default))
permanent redirect(301)
So, using url rewriting to change the link http://blog.test.com/ to http://www.test.com/blog/ is useless.
http://blog.test.com/
http://www.test.com/blog/
Although, you can achieve this using Apache Module mod_proxy.
The Apache Proxy Modules has these:
You need at-least mod_proxy and mod_proxy_http modules enabled for the proxy to work:
mod_proxy
mod_proxy_http
you should have lines similar to these in your apache's conf file:
conf
LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_module modules/mod_proxy.so
use this in your Virtualhost of http://www.test.com
Virtualhost
http://www.test.com
ProxyPass /blog http://blog.test.com ProxyPassReverse /blog http://blog.test.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.
mod_cache