Apache rewrite based on subdomain Apache rewrite based on subdomain apache apache

Apache rewrite based on subdomain


You should have a look at the URL Rewriting Guide from the apache documentation.

The following is untested, but it should to the trick:

RewriteCond %{HTTP_HOST} ^([^.]+)\.blah\.domain\.com$RewriteRule ^/(.*)$           http://blah.domain.com/%1/$1 [L,R] 

This only works if the subdomain contains no dots. Otherwise, you'd have to alter the Regexp in RewriteCond to match any character which should still work due to the anchoring, but this certainly feels safer.


Try this:

RewriteCond %{HTTP_HOST} (.+)\.blah\.domain\.comRewriteRule ^(.+)$ /%1/$1 [L]

@pilif (see comment): Okay, that's true. I just copied a .htaccess that I use on one of my projects. Guess it has a slightly different approach :)


@Sam

your RewriteCond line is wrong. The expansion of the variable is triggered with %, not $.

RewriteCond %{HTTP_HOST} ^([^\.]+)\.media\.xnet\.tk$            ^

that should do the trick