Q. What’s the best way to redirect domain.com to www.domain.com on the url address bar whenever someone omits or skip the www from domain.com? My site can be reached by two different URLs. For example http://domain.com/about/us.html and http://www.domain.com/about/us.html
How do I do configure Apache web sever vps for this task?
A. Apache (web server) 301 redirect is the most efficient and search engine friendly method for webpage redirection. You can place following code Apache’s httpd.conf vhost section or in .htaccess file.
$ vi .htaccess
Append following config code:
RewriteEngine on RewriteCond %{HTTP_HOST} ^domain.com RewriteRule ^(.*)$ http://www.domain.com/$1 [R=permanent,L]
Save and close the file. Above code will redirect users to www.domain.com url.
(adsbygoogle = window.adsbygoogle || []).push({});