For instance, what does --- mean?
It has no meaning, they are just seperating the variables.
- Code: Select all
RewriteCond %2---%{REQUEST_URI} !^(.+)---/\1(/.*)?$
This is kind of a simplistic explaination, you might want to read this:
http://www.regular-expressions.info/brackets.html (the "How to Use Backreferences" section).
First it makes a sting from the %2 variable (holding the name od the subdomain, eg. www.
richard.dom.com, that was matched in the line above), then there are three dashes (just to seperate it) and finaly the requested uri (eg
www.richard.dom.com/abc/def/). The final string would be "richard---/abc/def/".
Then on the other side, it creates another string, matching "richard" from the first string, and then putting it into the \1 place too, making "richard---/richard/*" (where * can be anything), as long as they don't match mod_rewrite will continue.
This is because once mod_rewrite has made the rewritten the url ("richard.DOMAIN/file.php" to "richard.DOMAIN/richard/file.php") it goes through mod-rewrite again, and would match again (without this RewriteCond) causing an infinite loop.
- Code: Select all
RewriteRule .* /%2%{REQUEST_URI} [QSA,L]
.* matches everything, because if it is a subdomain, it will need applying to all paths.
%2 still has "richard" in it. and REQUEST_URI has "/abc/def/" in it, so it puts them together making "/richard/abc/def/", the real server path relative to your document root.
QSA appends the query string and L stops mod_rewrite.
The code becaomes a little simpler.
- Code: Select all
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?SUB$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.SUB$ [NC]
RewriteRule !^usr(/.*)?$ /usr/%2%{REQUEST_URI} [QSA,L]
The third RewriteCond is not needed. The Rewrite rule does not match requests for the /usr directory so infinite loops can't happen.