Uniform website URLs using mod_rewrite
While some people might type in "www.deekayen.net", others, like myself, don't type "www." anymore. Besides, telling someone your website address, starting with "www." is clumsy. Some people even leave off a W to say "ww.example.com". Worse yet, I've seen people actually listen and only type two w's. I use an Apache mod_rewrite rule to send a permanent redirect to users who type the "www.".
RewriteCond %{HTTP_HOST} !^deekayen.net [NC]RewriteRule ^/?(.*) http://deekayen.net/$1 [R=permanent,L]
The first translates to "if the URL you are requesting doesn't start with deekayen.net," followed by the second line triggered by the first, "then you must load http://deekayen.net/ instead. $1 will include the filename you requested. This is a permanent thing, so get used to it, because otherwise I'll keep redirecting you."
This rule can also be handy if you have multiple domain aliases for the same website. For example, I don't tell anyone about deekayen.com, but www.deekayen.com and deekayen.com both redirect under this rule to deekayen.net.


Post new comment