Which method is better to add "www." before domain name

Which method is better to add "www." before domain name - .htaccess files are extremely useful in many cases for users who either do not have root permissions or for users who simply aren't comfortable in making changes in their web server's configuration file. Trying to debug .htaccess not working isn't always the easiest thing to do, however, hopefully by checking the discuss below mentioned about htaccess, url, url-rewriting, cname, .htaccess common problems as well as the troubleshooting tips, you'll have a better grasp on what you may have to modify to get your .htaccess file running smoothly.Problem :


I have search through Google and found 2 methods to add www before domain name. First is by adding a CNAME and second is using rewrite mod in .htaccess file.



I just want to know which method is better to use or there is other method because I'm currently using standalone WordPress as my back end.


Solution :

You need both - the CNAME is a DNS record that points www.example.com to example.com's server so that if a browser tries to open www.example.com then it can find what server (IP address) it is stored on. The second is a rule on the server that says "if someone loads example.com, tell them that they should have loaded www.example.com"



not only with CNAME records, but also you can put .htaccess code for redirection:



<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %HTTP_HOST !^www.
RewriteRule ^(.*)$ http://www.%HTTP_HOST/$1 [R=301,L]
</IfModule>


This is a 301 redirect (which is permanent redirect.) After a few weeks the site will be visible with www in Google Search from that time.


Additionally, if you would like to do some further testing, give the htaccess tester tool a try. It allows you to specify a certain URL as well as the rules you would like to include and then shows which rules were tested, which ones met the criteria, and which ones were executed.

Comments

Popular posts from this blog

Rewrite in Mediawiki, remove index.php, .htaccess

.htaccess rewrite wildcard folder paths from host

Using .htaccess to set a cookie and 301 redirect