how to make more complex and dynamic rewrites using $1, %1, %2 etc.
I'm trying to make a more dynamic rewrite (got a lot of domians pointing to the same server/site)
# put 'www' as subdomain if none is given
RewriteCond %{HTTP_HOST} ^([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [L,R=301]
# rewrite subdomains
RewriteCond %{HTTP_HOST} ^(admin|files|imap|mysql)\.[^\.]+\.[^\.]+$ [NC]
RewriteCond %{REQUEST_URI} !^/_(admin|files|imap|mysql)/ [NC]
RewriteRule ^(.*)$ /_%1/$1 [L]
# redirect to subdomain
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$ [NC]
RewriteCond %{REQUEST_URI} ^/_([^/]*)/ [NC]
RewriteRule ^(.*)$ http://%1.domain.com/ [L,R=301]
# rewrite 'secure' subdomain
RewriteCond %{HTTP_HOST} ^(demo|secure)\.[^\.]+\.[^\.]+$ [NC]
RewriteCond %{REQUEST_URI} !^/_secure/ [NC]
RewriteRule ^(.*)$ /_secure/$1 [L]
but now I'm confronting a problem..
by #redirect to subdomain
I can't figure out how to solve the condition and rule like the other I have made.. somehow I need to extract the domain from the first condition and then use it in the rule with %1, but how can you do that when you got another condition in between?
The capture data for
%1
etc is used from theRewriteCond
immediately above theRewriteRule
.Is there any reason your URI path evaluation/capture can't just occur in the
RewriteRule
? Something like this (I think this is what you're going for?):