Something like this works for the index page:
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName http://www.example.com
</VirtualHost>
So a url like this:
http://example.com gets forwarded to
http://www.example.com
but this doesn't work:
http://example.com/robots.txt
I have also tried the following in .htaccess with the same results:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
Please help me resolve this.
Full configuration:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so
LoadModule proxy_balancer_module /usr/lib/apache2/modules/mod_proxy_balancer.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com
</VirtualHost>
<VirtualHost *:80>
ServerName http://www.example.com
ProxyPass / balancer://example/ stickysession=JSESSIONID|jsessionid
ProxyPassReverse / balancer://example/ stickysession=JSESSIONID|jsessionid
ProxyPreserveHost On
<Proxy balancer://example>
BalancerMember http://host1.example.com:8080/ route=tomcat1
BalancerMember http://host2.example.com:8080/ route=tomcat2
</Proxy>
</VirtualHost>
robots.txt is located on each of the tomcat servers.