Forum Moderators: phranque
Example:
Real path: [mike.domain.com...]
Path in user's browser: [mike.domain.com...]
I tried to do like this:
RewriteCond %{HTTP_HOST} [^.]+\.domain\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ([^.]+)\.domain\.com(.*)$ index.php?user=$1 [L,NC] - LIKE THIS IT WORKS
RewriteRule ([^.]+)\.domain\.com/images(.*)$ users/$1/images/$2 [L,NC] - BUT LIKE THIS DOESN'T (infinite loop)
Why?
You will need to arrange for some part of the input URLs to be different from the output URLs. This is needed in order to prevent looping. In the case of the second rule, you can test for the presence of "/users/" and by-pass the rewrite if it is already present. In the case of the first rule, you can look for the presence of the "user=" querystring name.
After mod_rewrite rewrites a URL, control is passed back to httpd.conf, and then down through any/all .htaccess files in the new URL's filepath. This must be done in order to check for further RewriteRules or other access-control directives that match the new URL-path. So, that is why the rule loops.
I'd also suggest, you add another RewriteCond to exclude rewrites on the "www" subdomain, unless you really want to treat that as a "user."
Maybe the above will help. If not, please describe what you are trying to accomplish, and give several examples if you have more than one (or more than one kind) of rule you want to apply.
Jim