I need to set an environment variable to equal part of a domain. In pseudo code it would look something like this: m/(.*)\.(.*)\.(.*)$/m # subdomain=$1 domain=$2 # tld=$3 Or in other words: given www.abc.com, I want to extract 'abc' and store it in a variable. I think something like this is on the right track: RewriteCond %{HTTP_HOST} ^(.*)\.(.*)\.(.*)$ RewriteRule .* - %{E=domain:$2} Of course the above doesn't work or I wouldn't be asking for help. It would actually be nice to grab all parts with something like: RewriteRule .* - %{E=subdomain:$1}.%{E=domain:$2}.%{E=tldomain:$3} but for my purposes I just need the middle part. Any help greatly appreciated!
Update, I made some progress and can set the env. variable now. The two lines below does it nicely. I only use 'domain' but I thought I would make this more universal. RewriteCond %{HTTP_HOST} (.*?)\.?([^.]+)\.([^.]+)$ RewriteRule ^ - [E=subdomain:%1,E=domain:%2,E=tldomain:%3] But the problem comes up when I try and use the variable in code as you can see below... This works, the original line of code: RewriteCond %{HTTP_HOST} !^((www|reg|stage|svn)\.abc\.(com|net|org))|((abc|svn-abc)\.mywebsite\.com)$ [NC] This doesn't, the code with the env. variable in it (one place only for now): RewriteCond %{HTTP_HOST} !^((www|reg|stage|svn)\.%{env:domain}\.(com|net|org))|((abc|svn-abc)\.mywebsite\.com)$ [NC] Anyone know how to make this work?