Redirecting non-www to www through .htaccess
Last updated on Dec 3, 2014
I get this question a lot, so I’m now writing this post to use as a reference. Here’s how to redirect yourdomain.com to www.yourdomain.com.
Step 1: Open Notepad or your favorite text editor and paste the following code:
RewriteEngine On RewriteCond %{HTTP_HOST} ^yourdomain\.com [NC] RewriteRule ^(.*) http://www.yourdomain.com/$1 [L,R=301]
Step 2: Save the file as “.htaccess”
Take note that it’s not supposed to be “htaccess.txt,” or any other file name with another extension. It’s just “.htaccess”
Step 3: Upload the .htaccess file to your website’s directory. Your site should now be redirecting all yourdomain.com requests/visits to www.yourdomain.com.
Leave a Reply