Forum Moderators: phranque
### Reserved Subdomains ###
RewriteCond %{HTTP_HOST} RewriteCond %{HTTP_HOST} ^(groups如ortal在oards妃y夙uide好ews)\.example\.com(/)?([A-Za-z0-9-]+)?/?([A-Za-z0-9-]+)?
RewriteCond %{REQUEST_URI} !^/index.php.*
RewriteRule ^(.*) index.php?l=%1&s=$1&sub=$2 [L,QSA]
With this code, the following URLs work:
#1 [portal.example.com...]
#2 [portal.example.com...]
#1 rewrites to index.php?l=portal&s=&sub=
#2 rewrites to index.php?l=portal&s=users&sub=
However, the following URLs do not work:
#3 [portal.example.com...]
#4 [portal.example.com...]
#3 rewrites to index.php?l=portal&s=users/&sub=
#4 rewrites to index.php?l=portal&s=users/0607&sub=
#3 should rewrite to index.php?l=portal&s=users&sub=
#4 should rewrite to index.php?l=portal&s=users&sub=0607
It seems to me that the first "([A-Za-z0-9-]+)?/" is grabbing too much for $1 ($1 = "users/" and "users/0607" instead of just "users"), despite only allowing A-Za-Z0-9-.
However, I have no idea why this ($1 representing everything after the trailing / after example.com) is happening. Any ideas?
[edited by: JeNeSaisLaw at 9:26 pm (utc) on June 5, 2008]
[edited by: jdMorgan at 12:30 am (utc) on June 6, 2008]
[edit reason] One more example.com [/edit]
RewriteCond %{HTTP_HOST} RewriteCond %{HTTP_HOST} ^(groups如ortal在oards妃y夙uide好ews)\.example\.com[i](/)?([A-Za-z0-9-]+)?/?([A-Za-z0-9-]+)?[/i]
Jim
%1 refers to the string matching the first parenthesized sub-pattern in the last-matched RewriteCond, while $2 refers to the string matching thesecond parenthesized sub-pattern in the last-matched RewriteCond.
Therefore, your $1 is working as it should, while $2 is blank, and %1 and %2 will both be empty, because the URL-path is never present in the HTTP_HOST variable.
Jim
Here is the correct, current code:
### Reserved Subdomains ###
### Line one is supposed to grab the subdomain only if it matches one of groups, portal, boards, my, guide, or news. It is also supposed to grab the first and second set of alphanumeric characters (and hyphens) that trail example.com
RewriteCond %{HTTP_HOST} ^(groups如ortal在oards妃y夙uide好ews)\.example\.com(/)?([A-Za-z0-9-]+)?/?([A-Za-z0-9-]+)?
### Line two is supposed to prevent a loop
RewriteCond %{REQUEST_URI} !^/index.php.*
### Line three is supposed to take the content of the subdomain, set it to "l" (with %1), and then set the first and second set to "s" and "sub", respectively.
RewriteRule ^(.*) index.php?l=%1&s=$1&sub=$2 [L,QSA]
Currently, this works for both "l" and "s", but not "sub". $2 is blank.
[edited by: JeNeSaisLaw at 5:11 am (utc) on June 6, 2008]
For future reference for people:
RewriteCond %{HTTP_HOST} ^(groups¦portal¦boards¦my¦guide¦news)\.example\.com
RewriteCond %{REQUEST_URI} !^/index.php.*
RewriteRule ^([A-Za-z0-9-]+)?/?([A-Za-z0-9-]+)?/? index.php?l=%1&s=$1&sub=$2 [L,QSA]
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{HTTP_HOST} ^(groups如ortal在oards妃y夙uide好ews)\.example\.com
RewriteRule ^([a-z0-9-]+/)?([a-z0-9-]+)?/? index.php?l=%1&s=$1&sub=$2 [NC,L,QSA]
Since REQUEST_URI will never contain anything but the URL-path --i.e. it will never contain the query string-- I removed the meaningless (in this case) ".*" on the end of "^/index\.php.*" and end-anchored it to to disambiguate the pattern so it matches one and only one URL-path --exactly "/index.php"-- and nothing else.
Jim