stevedoria.net

reused, like this site's design

Getting Around Without RedirectPermanent

It seemed that I would be unable to persuade an ISP technical support representative to change their server configuration, while talking with him at 4am. Setting up a 301 redirect between a domain with a www subdomain and a domain without a subdomain is pretty easy. I usually do something like the following when setting up virtual web hosts to enhance SEO for a particular domain:

<VirtualHost 11.22.33.44:80>
   ServerName stevedoria.net
   RedirectPermanent / http://www.stevedoria.net/
</VirtualHost>
<VirtualHost 11.22.33.44:80>
   ServerName www.stevedoria.net
   DocumentRoot /home/stevedoria.net/www
   # Other server directives...
</VirtualHost>

Luckily enough for me, the ISP allows shared hosting clients to use an .htaccess file and has mod_rewrite enabled. I’m pretty sure that people have used mod_rewrite to effect the same results as the configuration above, but after a couple of minutes searching for the appropriate solution on Google, I figured that it might take less time to derive the solution for myself with the Apache Web Server documentation. Here’s my solution of permanently (301) redirecting a non-www domain to the corresponding domain with a www subdomain:

RewriteCond %{HTTP_HOST} ^stevedoria.net$
RewriteRule ^/?(.*)$ http://www.%0/$1 [L,R=301]

Leave a Reply