Redirect all traffic comming to domain.com to www.domain.com using apache mod_rewrite

Published on Author Akhil Bansal2 Comments

You may want to redirect all visitors to coming to your domain “domain.com” to “www.domain.com”. Most popular way to do this is using apache’s mod_rewrite module. You just need to add few lines in your apache’s configuration file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule ^(.*)$ http://www.domain.com$1 [R=permanent,L]

2 Responses to Redirect all traffic comming to domain.com to www.domain.com using apache mod_rewrite

  1. And if you need to do this for Passenger (which disables mod_rewrite by default), simply delete the Rails public/.htaccess file and then enable the RailsAllowModRewrite configuration parameter.

Leave a Reply

Your email address will not be published. Required fields are marked *