Need help with mod_rewrite

My objective is to have all visitors going to mysite.com be forwarded to www. mysite.com
Same with https. I’m attempting to have it achieved with the mod_rewrite in the /etc/apache2/default-server.conf with a weird result. It works well for https, however it does not for http. Would anybody be able to point me in the right direction?

here is the code:

RewriteCond %{HTTPS} on
 RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
 RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
 RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
 RewriteCond %{HTTPS} Off
 RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC,OR]
 RewriteCond %{HTTP_HOST} dev1\.mysite\.com$ [NC]
 RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

polren6 wrote:
> My objective is to have all visitors going to mysite.com be forwarded to
> www. mysite.com
> Same with https. I’m attempting to have it achieved with the
> mod_rewrite in the /etc/apache2/default-server.conf with a weird
> result. It works well for https, however it does not for http. Would
> anybody be able to point me in the right direction?
>
> here is the code:
>
>
> Code:
> --------------------
> RewriteCond %{HTTPS} on
> RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} dev1.mysite.com$ [NC]
> RewriteRule ^(.)$ https://www.mysite.com/$1 [R=301,L]
> RewriteCond %{HTTPS} Off
> RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
> RewriteCond %{HTTP_HOST} dev1.mysite.com$ [NC]
> RewriteRule ^(.
)$ http://www.mysite.com/$1 [R=301,L]
>
> --------------------

i probably should remain silent (because i know nothing about apache
configuration–nor why you would want to ‘forward’ once inside, rather
direct to the same IP before)…BUT, can’t you do what you wish by
setting the DNS records for the domain mysite to have both mysite.com
and www.mysite.com resolve to the same IP??

that is the way i do it,

DenverD

Thanks DenverD, I appreciate it.

Now this is most likely stupid to ask but did you remember to enable rewriting on the default host as well as the SSL vhost?