Redirect to

To redirect (rewrite) a subdomainless site to the www prefixed one with apache, use mod_rewrite. This must be enabled in Apache’s conf file, and allowed to override the defaults with AllowOverride in the relevant directory section. Line 5 checks to see if URL patter matches (if !not then line 6 rewrites it.

# If it isn't already
RewriteEngine On

# If !not then 301 to
RewriteCond %{http_host} ! [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Codemonkey of Node.js, Django, PHP and all things HTML5 Solving tech challenges, one bit at a time.

Posted in .htaccess, apache, linux Tagged with: , , , , , ,

Leave a Reply

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