On the simple side I'm trying to redirect (or rewrite) everything from non-www to www. I found sample code (see below), but it doesn't work most of the time.
The base domain is one server/IP address, while "www" is on a different server/IP address. I would like requests to example.com to auto forward to www.example.com so it points to the correct server. The content on the "www" server does not exist on the base server, but there is an old website that we are migrating from (with different content).
I've tried various sample code, but the redirect only happens when I specify a URL that matches a file on the base server. Nothing is redirected otherwise.
For example, here is code I tried that rewrites base URL to www:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This only works with a URL such as: example.com/avalidfileonoldserver.htm, but does not work with
example.com or example.com/fileonlyonnewserver.htm
In case it matters, the old server is a ruby on rails application.
Any ideas?
Thanks.