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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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