Type your domain name without www in address bar. Check whether it redirects to your site or give a 301 error message. If you got 301 error message, then you will solve this problem using .htaccess.
Syntax:
RewriteEngine On
RewriteCond %(HTTP_HOST) ! ^www.domainname.com$ [NC]
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L, R=301]
Explanation:
Where,
.htaccess force the all http requests to use either www.domainname.com or domainname.com .
HTTP_HOST - represents your domain name.
RewriteCond - check the conditions if you typed domain name is not start with www, it
redirect to next rewrite rule.
! ^www.domainname.com$ - means you typed domain name is not start with www.
NC - represents not case sensitive.
RewriteRule - means it redirect domain name without www to http://www.doaminname.com.
^ - starting
.* - one or more characters.
$ - ending
L - if rule matches, don't process any other rewrite rules below this one.
L - if rule matches, don't process any other rewrite rules below this one.
R=302 - redirect code
Related Post:
Related Post:
What is htaccess?
Restrict users to access pages from site using .htaccess
Compressing resource with gzip using .htaccess
How to create error document using .htaccess
How to add expires headers using .htaccess
How to add MIME types using .htaccess
How to enable SSI using .htaccess
How to force script to display as source code using .htaccess
How to prevent access to php.ini file using .htaccess
How to enable or disable directory list using .htaccess
How to redirect urls using .htaccess
How to enable short tag in php using .htaccess
How to access pages through one page in site using .htaccess
Restrict users to access pages from site using .htaccess
Compressing resource with gzip using .htaccess
How to create error document using .htaccess
How to add expires headers using .htaccess
How to add MIME types using .htaccess
How to enable SSI using .htaccess
How to force script to display as source code using .htaccess
How to prevent access to php.ini file using .htaccess
How to enable or disable directory list using .htaccess
How to redirect urls using .htaccess
How to enable short tag in php using .htaccess
How to access pages through one page in site using .htaccess