Sometime we just can’t control the client is accessing our website either
via www or just without www.

In virtualhost setting for apache this can be done by adding the following line into
httpd.conf

<VirtualHost *:80>
    ServerAdmin webmaster@namran.com
    DocumentRoot /home/namran/public_html/namran.com
    ServerName namran.com
    ServerAlias www.namran.com
 
    ErrorLog logs/namran.com-error_log
    CustomLog logs/namran.com-access_log common
 
</VirtualHost>