Redirecting a URL to a subdomain regardless of Virtual Domain

I’m trying to redirect to

It needs to work on all virtual domains.

This is what I have so far

RewriteCond %{REQUEST_URI} ^/rc(/?)$ [NC]
RewriteRule ^(.*)$ http://webmail.%{HTTP_HOST} [R=302,L]

This works for which is correctly rewritten to

but it doesn’t work for which becomes

Can anyone show me how to do this please?

Kind regards,


RewriteCond %{REQUEST_URI} ^/rc [NC]
RewriteRule .? http://webmail.hardcode-the-domain.tld [R=302,L]

That should work if you actually put the domain instead of using HTTP_HOST to fill it in. (HTTP_HOST will contain the www subdomain)

True, but that’s not going to work in my global httpd.conf for all virtual subdomains.

Lets see you config (httpd.conf) for these virtual domains.

RewriteEngine on

# Removing "www" subdomain.
RewriteCond %{HTTP_HOST} ^www\\.(.+)$ [NC]
RewriteRule .? http://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_URI} ^/rc [NC]
RewriteRule .? http://webmail.%{HTTP_HOST} [R=302,L]

This is one of them. They each have their own .conf files

<VirtualHost *:80>
        DocumentRoot /var/www/html/www/public
        ScriptAlias /cgi-bin/ /var/www/html/www/public/cgi-bin/

        CustomLog /var/log/httpd/sites/www.bytes bytes
        CustomLog /var/log/httpd/sites/www.log combined
        ErrorLog /var/log/httpd/sites/www.error.log

        <Directory /var/www/html/www/public>
                Options +Includes -Indexes

I’m hoping to put the solution in the main httpd.conf though.