By a tradition which is very similar to the "We have always worn these funny hats, so we always will" line of thought many website addresses begin with www dot. This is changing as people ask why have a redundant www tacked on the front of an address.
However why make a user type more than they have to? So to that end I Googled ages ago and found http://no-www.org/. Which provided the code below to add to my .htacess file in my web root.
The basic effect is if someone types http://www.jamesmcdonald.id.au into their browser they will be redirected to https://toggen.com.au/blog
Obviously you will need to have your mod_rewrite module enabled in your apache httpd.conf file and also "AllowOverride All" to allow the .htaccess file to actually do a redirect.
<ifmodule mod_rewrite.c>
RewriteEngine OnRewriteBase /
# This is hostname rewrite that strips off the leading www and returns
# the corrected URL along with the whatever path they were looking for.
RewriteCond %{HTTP_HOST} ^www.jamesmcdonald\.id\.au$ [NC]
RewriteRule ^(.*)$ https://toggen.com.au/$1 [R=301,L]</ifmodule>
This is the code as recommended by no-www.org. Which will do the rewrite for anyhost given to it. I have explicitly defined my domain name in my install.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
0 Comments