Forum Moderators: phranque
Is it possible to use RewriteCond backreferences to make the mapping generic, e.g.
www.mydomain1.com => /mydomain1
www.mydomain2.com => /mydomain2
I tried this
RewriteEngine On
RewriteCond ${HTTP_HOST) ^(www\.)?(.*)\.(com¦org¦net) [NC]
RewriteCond ${REQUEST_URI}!/(%2)/
RewriteRule (.*) /%1/$1 [L]
and it didn't work.
Welcome to WebmasterWorld!
Yes and no. You can do it if either:
a) Your code is placed in httpd.conf
b) Your server is running FreeBSD or another *nix OS with POSIX 1003.2 regular-expressions support.
In mod_rewrite, variables may appear only on the 'left side' of a RewriteCond, and there is no built-in 'equality test' function. However, if your server supports POSIX 1003.2 regex, then there is a very tricky work-around, as described in this thread on how to Rewrite an arbitrary subdomain to a unique subdirectory [webmasterworld.com]. This depends on POSIX 1003.2's "atomic back-reference" and is not available on many, if not most, *nix servers.
If at all possible, you should simply define virtual servers in httpd.conf, rather than using this method; Even if you get it working on your current server, you could have problems if that server is 'upgraded' to a different *nix 'flavor' in the future, and the new OS does not support POSIX 1003.2. (Happened to me)
Jim
In this case I don't have access to the apache .conf files. My ISP allows the use of three domains (+ the user subdomain they assign) on the web space they provide. On the HTML only server they will map the domain names to a folder (presumably with a vhost entry), but on the CGI server they will only map the domain name to the main document root folder.
A single set of generic rules would have been nice, however three sets of rules will not be a big problem.