Forum Moderators: phranque

Message Too Old, No Replies

Rewriting subdomain and folder to file

         

Shawazi

7:13 pm on Oct 22, 2007 (gmt 0)

10+ Year Member



I have a RewriteCond like this

RewriteCond %{HTTP_HOST} (groups)\.example\.com
RewriteRule (.*) page.php?var=$0

$0 is only returning page.php. This will only output page.php. But I want users to type in:

groups.example.com/mygroup

so that $0 is page.php?var=mygroup and $1 is just mygroup

I tried putting the extra () in the RewriteCond but didn't have luck.

[edited by: jdMorgan at 7:32 pm (utc) on Oct. 22, 2007]
[edit reason] example.com [/edit]

jdMorgan

7:32 pm on Oct 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$0 is undefined; Use $1 through $9 only.

The parentheses in your RewriteCond are unnecessary, unless you use the %1 back-reference, or wish to make the subdomain "groups" optional by following the parentheses with a "?". I this latter case, the pattern should read "(groups\.)?example.com".

If that is not part of your purpose, then I'd suggest:


RewriteCond %{HTTP_HOST} ^groups\.example\.com
RewriteCond $1 !^page\.php$
RewriteRule (.*) page.php?var=$1

The new (second) RewriteCond prevents recursion, which would otherwise lead to a server error.

Jim