How to redirect non-www site to www site?

I have created one wordpress site.
As I write domain name without www then it opens correctaly
but as I write www. in url it’s not showing the site.

Please help me..
Thank you in advance.

Read More

I have edited my question and added the following part :

Following is my file :
Where I have to put code provided by you ?
I tried it before the “Begin WordPress” line but still not working.

.htaccess

“# -FrontPage-“

IndexIgnore .htaccess /.?? *~ *# /HEADER */README* */_vti*

order deny,allow

deny from all

allow from all

order deny,allow

deny from all

AuthName example.com

AuthUserFile /home/example/public_html/_vti_pvt/service.pwd

AuthGroupFile /home/example/public_html/_vti_pvt/service.grp

“# BEGIN WordPress”

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ – [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

“# END WordPress “

Related posts

Leave a Reply

5 comments

  1. This happens when your DNS has insufficient configuration.
    Your site already has an A record (“example.com” that points at some IP).

    But you also need to make the www-part work by adding a CNAME record. CNAME can be configured in two basic ways:

    So you have:

    A Record

    Host: example.com
    IP: 5.5.5.5
    

    CNAME

    Host: *.example.com (or www.example.com)
    

    Remember also to add a MX record if you want to configure the mail domain.

  2. Try to follow below steps:

    1) Add CNAME record for www and set value/points to as @. OR you can do vice-versa
    2) Under WordPress, Set your domain with www under Home and Site URL. e.g. http://www.example.com
    3) Add redirect code in .htaccess

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

    In WordPress, #3 is optional. WordPress will manage automatically to open site with www if you set as per #2.