How to redirect/rewrite to the FQDN URL without setting ServerName

apache-2.2fqdnhostnamemod-rewriteredirect

Often in intranets, users will direct URLs to a hostname without supplying the FQDN. Example:

http://internalHost

Instead of

http://internalHost.example.com

I would like to redirect users / rewrite URLs so that everything will use the FQDN. Here's the catch: I don't want to set ServerName explicitly. (This is for a product which will be deployed in multiple intranets so we can't know the value of ServerName ahead of time).

According to: http://wiki.apache.org/httpd/CouldNotDetermineServerName Apache uses a reverse lookup to determine a default FQDN.

How can I make use of/reference that FQDN that Apache is using for a mod_rewrite or redirect?

Best Answer

I would suggest you read about UseCanonicalName.

http://httpd.apache.org/docs/current/mod/core.html#usecanonicalname

Probably the option

UseCanonicalName DNS

Should be sufficient (as Apache will by itself already generate a redirect)

De documentation also mentions that UseCanonicalName influences what ends up in the SERVER_NAME variable name, which you could use in a rewriterule.