Redirect from HTTP to WWW

http to www

Let’s say you have a website on http://www.mywonderfulwebsite.com. I’m sure you must have realized that people can go to your site by going http://mywonderfulwebsite.com (without the www prefix). In fact, most people are so lazy typing the full path on their browser and normally just type “mywonderfulwebsite.com”.  I do this all the time too.

Did you know though that having these 2 “separate locations” is bad for search engines and also for web development purposes? I had this problem with my church website where people couldn’t log in when the URL was typed without the www prefix (cookie & sessions problem).

So here is how you do a permanent redirect (301) of your URL automatically from http to www.

Don’t be intimidated if you don’t understand what a permanent redirect (301) means. It simply means a redirection or a permanent move but it’s very search engine friendly. To do a 301 Redirect from http to www, you need to create an .htaccess file (or modify the current one), add a few lines to the file, and save it on your root folder where you store your website files (normally in a folder called public_html).

How to redirect from http to www

Add these lines to the .htaccess file to redirect from http to www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^mywonderfulwebsite.com
RewriteRule (.*) http://www.mywonderfulwebsite.com/$1 [R=301,L]

(of course, change the mywonderfulwebsite.com to your real domain name.

Done! Plain and simple. To test and see if it works, type your URL without the www part and see whether the URL changes automatically.

PS: This guide to redirect from http to www is of course, assuming you are hosted on a Linux server.

About Michael Aulia

Owner of CravingTech.com, Michael is a tech enthusiast who blends a love for gadgets with a passion for gaming. With insightful articles and professional reviews, he navigates the digital landscape, offering expertise on consumer electronics and gaming trends.

Comments are closed.

Share via
Copy link