Mod_rewrite To External Domain Using Part Of An Existing Domain

Joined: 11/28/2008

I usually point my sites that require email to Google Apps. I've added CNAME records to the DNS to point mail, docs, and calendar appropriately, but I also want to have a wildcard subdomain match so that all subdomains are sent to my VPS and handled there (this way I don't have to add a record for each subdomain that I may create). I'm using VirtualDocumentRoot so that I can map any subdomain to a domain instantly by adding a folder, without ever having to touch my apache config. I could create an .htaccess file to redirect accordingly, but I'd have to do this for every single domain that I have now and any I add in the future; it's a tedious solution to say the least.

What I want is to capture any mail, docs, or calendar subdomain and rewrite or redirect them to the proper Google App page. I can't seem to figure out how my rule needs to be written. My condition appears to be working, but I have a feeling even that could be wrong since I tested it against a simple expression and had nothing after my domain name:

CODE
RewriteCond %{HTTP_HOST} ^mail\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]

Any ideas? Thanks.

Who can bring a charge to God's elect? It is God who justifies!

Joined: 11/28/2008
I would say that you could

I would say that you could simplify your condition since you only need it to start with mail. as opposed to finishing with something, so perhaps:

CODE
RewriteCond %{HTTP_HOST} ^mail\. [NC]
RewriteRule ^(.*)$ http://www.domain.com$1 [R=301,L]

I am not clear if you are getting errors with what you have?

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
This rewrite needs to apply

This rewrite needs to apply to any and all domains that are accessed, not a specific domain, so my problem is in the rule getting the domain name after mail.

Who can bring a charge to God's elect? It is God who justifies!

Joined: 11/28/2008
Ok, I think you can use

Ok, I think you can use something like the example here:
http://httpd.apache.org/docs/2.2/rewrite/r...html#uservhosts

By using 2 rewrite_rules, the first adds the host name to the front of the full address that is then used in the second rule.

Paul Davey
Whitford Church
"Everyone who calls on the name of the Lord will be saved." Romans 10:13
"For all have sinned and fall short of the glory of God, and are justified

Joined: 11/28/2008
Thanks, I'll try that out.

Thanks, I'll try that out.

Who can bring a charge to God's elect? It is God who justifies!