0

I have the following:

<VirtualHost *:80>
        DocumentRoot /var/www/webmaster/example.com/web

        ServerName example.com
        ServerAlias www.example.com
        ServerAdmin webmaster@example.com

        <Directory /var/www/webmaster/example.com/web>
                Options  +ExecCGI
                AllowOverride All
                Require all granted
        </Directory>

         RewriteCond %{HTTP_HOST} ^example.com [NC]  
         RewriteRule ^(.*) http://www.example.com$1 [last,redirect=301]

</VirtualHost>

However when I view http://example.com it stays at http://example and does not go to http://www.example.com

This is even after trying all the other mentioned posts such as: apache redirect from non www to www

Community
  • 1
  • 1
John Crawford
  • 9,656
  • 9
  • 31
  • 42
  • you're basically saying `if http_host = example.com, redierct`. You need `if http_host IS NOT example.com`, e.g. `RewriteCond %{HTTP_HOST} !^example.com$` – Marc B May 05 '15 at 14:23
  • @MarcB Sorry I did have that (failed copy n paste). I tried your "~^example.com" (I thought it would be "! instead of a ~" but that also didn't work. – John Crawford May 05 '15 at 14:31
  • yeah, `~` was a typo from trying to type up the comment and talking on the phone. for my next trick: chewing gum and blinking at the same time. – Marc B May 05 '15 at 14:33

0 Answers0