user121196 user121196 - 1 year ago 102
Apache Configuration Question

apache redirect from non www to www

I have a mortgage calculator site that doesn't seem to redirect from to

My apache config is as follows:

RewriteEngine On
### re-direct to www
RewriteCond %{http_host} !^ [nc]
RewriteRule ^(.*)$$1 [r=301,nc]

What am I missing?

Answer Source

Using the rewrite engine is a pretty heavyweight way to solve this problem. Here is a simpler solution:

<VirtualHost *:80>
    Redirect permanent /

And then you'll have another <VirtualHost> section with ServerName for your real server configuration. Apache automatically preserves anything after the / when using the Redirect directive, which is a common misconception about why this method won't work (when in fact it does).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download