You can tray this example,which I am using on my content delivery network (CDN) server ME2J.com.
Few weeks ago I wrote how to remove WWW from domain with .htaccess. In some cases or hosting plans it’s not possible to view or use .htaccess file (e.g. some low cost or free hosting providers). Solution is PHP code which redirects all www requests to non www page.
Another good thing about removing double content is to remove or add www prefix to your domain. PHP version is here Remove WWW from domain This is what I now use for all my domains – domain without www prefix. Add WWW to domain This probably is best for old domains like mine www.rolandinsh.lv
Inspired by my discussion with Kaspars on his homepage konstruktors.com how to better remove index file. So I’ll post both versions, because they use different methods: with and with out RewriteEngine On.