1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Welcome to GadgetBit!

We are a community of technology enthusiats.

If you are already a registered member then you can login here

If you are new to the site then why not join up? It will only take a couple of minutes to register, by doing so all adverts will be removed from the site. You can register here or you can use your Facebook or Twitter account.

How to always prefix www. in front of your domain

By Creaky · Oct 11, 2015 ·
Tags:
  1. Creaky
    In this tutorial we show you how to redirect any traffic going to your domain without the www. ,even if it is typed in without it, this code will automatically add it for you.

    The following code needs to be added to your exisiting .htaccess file. If you dont currently have this file then do the following
    1. Create an empty text file using a text editor such as notepad, and save it as htaccess.txt.[/*]
    2. If using a text editor, be sure to save the file as plain text.[/*]
    Once you have created the file rename it to .htaccess, note the .txt has been removed. The file must have this name to work correctly.

    Add the following code to the file and upload to your server.
    Code:
    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
    
    RewriteCond %{HTTP_HOST} ^www.domain.com$
    
    RewriteRule ^/?$ "http://www.domain.com" [R=301,L]
    Now, all your traffic will be redirected to the full domain and prefixed with www.

    Share This Article