OUR BUSINESS is building mobile solutions for YOUR BUSINESS

The internet is going mobile. Give your business the edge - Whether you need to mobile enable your customers, suppliers or staff, we can design and build YOUR SOLUTION... Websites, iPhone and Android.

Configuring Apache2

Configuring Apache2 Virtual Host to force non-www URLS

I don't know about you, but I have a bit of a bias against using .htaccess files to force rewrite rules. Using .htaccess forces the web server to check for an .htaccess file for every file served, and not only do they have to check the directory your file is in, they also have to check the entire parent directory tree for the .htaccess files. That adds a lot of overhead to every file request.

After days of looking for a better way of forcing the URL's on my website to be http://bgies.com/somefile... instead of http://www.bgies.com/somefile I finally found a really good way of doing it. Of course, this method requires you to have root access to your server, but I just switched from using a shared host to using a cloud-based virtual server, so I now have complete access to everything.

Why do you want to do this? Well.. if you have been following discussions about search engine optimization you will know it's something you should do. Your pages will look a lot more popular to Google if all the hits are for one page, not one with www and one without. In my case I'm using Google Maps in a lot of my applications, and Google Maps has a problem if your key is for a website with www and you send a request from a non www page, so it's much simpler to just force the non-www for all pages. Trust me, there are a lot of good reasons to force one or the other.

If you want the www in the URL for all your pages (God knows why you would want them), but if you do just reverse my instructions :).

 

Please register or login to post comments