I'm trying to force the www. on only the production server. I do not want to affect the staging server's domain. Here is my current rule:
# Force www
RewriteCond %{HTTP_HOST} !^www.mydomain.com$ #production
RewriteCond %{HTTP_HOST} !^mydomain.s2.mycompany.com$ #staging
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301]
Basically, if the host isn't www.mydomain AND the host isn't mydomain.s2.... then I want to redirect to www.mydomain.com. With the code above, I'm getting a redirect loop.
Any ideas?
Add the "Last" or [L] flag to the RewriteRule like -
[R=301,L]
:That should stop the loop.
You can review the docs for
RewriteRule
directive (and others) here: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewriterule