Forum Moderators: phranque
This directs user.domain.com to his user directory. My question is what does ^/(.*)$ in the rewrite rule do.
If the URL was
[user1.domain.com...]
what are the values of %1 and $1
Thanks a bunch in advance.
Welcome to WebmasterWorld [webmasterworld.com]!
RewriteCond %{HTTP_HOST} !www.domain.com [NC] prevents the rewrite from taking place if the requested subdomain is "www".
RewriteCond %{HTTP_HOST} (.*).domain.com [NC] finds the subdomain (username) and places it into the backreference (variable) %1
RewriteRule ^/(.*)$ finds the requested page on your site and puts it into backreference $1
For your example, %1 would be "user1" and $1 would be blank. This will be redirected to [yourdomain.com...] [L]
If the requested URL was [user2.domain.com...] then %1 would be user2 and $1 would be foo.html. This will be redirected to [yourdomain.com...]
By the way, the RewriteConds have errors (relatively harmless, but errors) in them. They should should be:
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com [NC]
Note the backslashes required to escape the periods, which are special characters for the regular expressions used in mod_rewrite, and the start anchors "^" thrown in for good measure.
Ref: Introduction to mod_rewrite [webmasterworld.com]
HTH,
Jim