Redirecting non-www to www in IsapiRewrite

466 Views Asked by At

I am trying to redirect calls to http://mydomain.com to http://www.mydomain.com. Is there a simple way to do it in IsapiRewrite file?

I have tried the following but it is not working:

RedirectRule ^mydomain.com$ www.mydomain.com [R=301]

Also tried this:

RewriteCond %{HTTP_HOST} ^mydomain.com [I]

RewriteRule (.*) http\://www.mydomain.com$1 [I,RP]

Any idea what I am doing wrong.

Thanks!

1

There are 1 best solutions below

3
On

Here's the code:

RewriteEngine on

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]