RewriteCond %{HTTP_HOST} ^!mookal.com$ [NC]
RewriteRule ^(.*)$ http://www.mookal.com/$1 [R=301,L]
This starts with the HTTP_HOST
variable, which contains just the domain name portion of the incoming URL (example.com
). Assuming the domain name does not contain a www.
and matches your domain name exactly, then the RewriteRule comes into play. The pattern ^(.*)$
will match everything in the REQUEST_URI
, which is the resource requested in the HTTP request (foo/blah/index.html
). It stores this in a backreference, which is then used to rewrite the URL with the new domain name (one that starts with www
).
[NC]
indicates case-insensitive pattern matching, [R=301]
indicates an external redirect using code 301 (resource moved permanently), and [L]
stops all further rewriting, and redirects immediately.