Rewrite to using htaccess in Apache

Posted December 27, 2003 by Quinn McHenry in Apache web server

Last Updated on

You may want all visitors to your site using www in front of your domain name ( instead of just your domain name ( By implementing a simple .htaccess RewriteRule, visitors to will see the URL change in their browser as they are redirected to the correct URL.

To redirect a URL such as “” to “” use:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourdomain\.com
RewriteRule ^(.*)$$1 [R=permanent,L]

In the RewriteRule code, the R=permanent sets the type of redirection (permanent is 301; the default is temporary or 302). The L makes this the last Rule to use and stops rewrite processing.


About Quinn McHenry

Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
View more articles by Quinn McHenry

The Conversation

Follow the reactions below and share your own thoughts.

Leave a Reply