Apache – Redirect non-www to www Subdomain

Redirecting non-www to www url can be simply done by adding a virtual host configuration. For example, if i have a domain ykyuen.com and i want to redirect it to http://www.ykyuen.com, just add the following virtual host.

<VirtualHost *:80>
  ServerAlias ykyuen.com
  RedirectMatch permanent ^/(.*) http://www.ykyuen.com/$1
</VirtualHost>

 

Restart the Apache and it should work.

Done =)

Reference: StackOverflow – apache redirect from non www to www
http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www

One thought on “Apache – Redirect non-www to www Subdomain”

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.