how to redirect users to www domain automatically
Website URLs with www and without www are different for a web browser but usually they point to the same location on the server so any related issues might not be revealed for a long time.
Therefore before starting your website you have to decide what will be the primary domain for your website, will it include www or not. After choosing the domain name, the alternative domain names and a pure IP address have to redirect customers to the primary domain on opening any website page. For example, if you input ka-station.com to a browser address bar, you will see that the URL will change to www.ka-station.com because we chose the domain with www as a primary domain.
These redirects can be made in php code or in .htaccess file (for Apache web server). Changes in .htaccess are preferable and they should work slightly faster therefore we show here an example how to do a redirect from your domain name to a domain with www prefix in .htaccess.
Therefore before starting your website you have to decide what will be the primary domain for your website, will it include www or not. After choosing the domain name, the alternative domain names and a pure IP address have to redirect customers to the primary domain on opening any website page. For example, if you input ka-station.com to a browser address bar, you will see that the URL will change to www.ka-station.com because we chose the domain with www as a primary domain.
These redirects can be made in php code or in .htaccess file (for Apache web server). Changes in .htaccess are preferable and they should work slightly faster therefore we show here an example how to do a redirect from your domain name to a domain with www prefix in .htaccess.
RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} !^www RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]