Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

13 May 2010

Universal ALL DOMAIN rewrite for non-www to canonical/www using htaccess or https.conf on apache server


This took me a few days to get right. The lack of feedback from testing, along with browser caching and the general head wrecking-ness of Regex make htaccess rewrites like this a total pain in the ass. Anyway thanks to the guys over at the alt.apache.configuration newsgroup, I've managed this:

The code below will rewrite anything on your server that does not have a www. at the beginning to the same thing with a www. prefixed. Urls beginning with an IP address are left alone so that http://IPADDRESS/~username/ access still works.

Subdomains are also redirected to their www. equivalent however they should still resolve and work normally. (untested)

This is great if you run your own server and want to redirect everything at once or if you just want a template that you can use for all your websites without editing or altering.

My code works without too much Regex with makes it a lot less memory intensive than most "universal" mod_rewrites out there.

Continue Reading >
Cron Design Studio: Dublin based web design & software development