We need any .org
domain should redirect to .net
domain documentroot
I assume you mean "rewrite", as opposed to external "redirect", like the code in your question? (You've also reversed the direction of the required rewrite, as stated in your question, but anyway, I'll go with what you stated in comments... .org
to `.net)
This assumes that you only have single level TLDs, as referenced in your code (eg. .net
, .me
, .info
, .org
, etc) and not multi-level "TLDs" such as .co.uk
.
RewriteCond %{HTTP_HOST} !^[^.]+\.abc\.net [NC]
RewriteCond %{HTTP_HOST} !^[^.]+\.example\.me [NC]
RewriteCond %{HTTP_HOST} !^[^.]+\.mysite\.info [NC]
RewriteCond %{HTTP_HOST} !^[^.]+\.xyz\.org [NC]
RewriteCond %{HTTP_HOST} !\.internal$ [NC]
RewriteCond %{REQUEST_URI} !^/collateral/ [NC]
RewriteRule ^(.+) /var/www/domains/%{HTTP_HOST}/httpdocs/%{HTTP_HOST}/$1
Try something like the following instead:
# If any of these domains are requested then stop
RewriteCond %{HTTP_HOST} ^[^.]+\.abc\.net [NC,OR]
RewriteCond %{HTTP_HOST} ^[^.]+\.example\.me [NC,OR]
RewriteCond %{HTTP_HOST} ^[^.]+\.mysite\.info [NC,OR]
RewriteCond %{HTTP_HOST} ^[^.]+\.xyz\.org [NC,OR]
RewriteCond %{HTTP_HOST} \.internal$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/collateral/ [NC]
RewriteRule ^ - [L]
# Split the requested host into HOSTNAME + TLD (env vars)
RewriteCond %{HTTP_HOST} ^([^.]+\.[^.]+)\.([^.]+)
RewriteRule ^ - [E=HOSTNAME:%1,E=TLD:%2]
# Change TLD "org" to "net"
RewriteCond %{ENV:TLD} =org [NC]
RewriteRule ^ - [E=TLD:net]
RewriteRule (.+) /var/www/domains/%{ENV:HOSTNAME}.%{ENV:TLD}/httpdocs/%{ENV:HOSTNAME}.%{ENV:TLD}/$1 [L]
The first block of directives reverses your current conditions. ie. It says if the request is for any of "these domains" then stop processing, instead of... only rewrite when the request does not match any of "these domains". This makes the following rules simpler, since we now know that the requested host is one that we want to rewrite, so we don't need to litter the code with more conditions.
We then split the requested HTTP_HOST
into the hostname (subdomain + domain) and the tld only. And store these in two environment variables: HOSTNAME
and TLD
respectively.
We then test the TLD
env var and change this if necessary (ie. org
to net
).
And lastly, there is an unconditional rewrite to the appropriate document root and subdirectory (using the env vars assigned above), as in your code. Note that you stated just "document root" in your description, but your code also includes a subdirectory of the same name, so I've included the subdirectory as well.
This assumes the mod_rewrite directives stated in your question are complete. ie. There's no other dependent directives further down the config? I added the L
flag for good measure.