Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'd like to stop Apache from responding to

http://machineName. 

I'd prefer it to respond (or redirect?) to

http://machineName.something.com

In my case,

http://intra-beta 

should either repond or redirect to

http://intra-beta.domain.ca

Is this related to useCanonicalName ?

Here's a snippet of my httpd.conf

...

ServerName xxx.xxx.xxx.xxx:80

NameVirtualHost *:80

...

UseCanonicalName Off

...

<VirtualHost *:80>
    ServerName      intra-beta.domain.ca

    DocumentRoot "E:/web/intra/htdocs"
    ServerAdmin  admin@domain.ca

    ...
</VirtualHost>

<VirtualHost *:80>
    ServerName   intra.otherDomainFr.ca

    DocumentRoot "E:/web/intra/htdocs"
    ServerAdmin  admin@domain.ca

    ...
</VirtualHost>

<VirtualHost *:80>
    ServerName   intra.otherDomainEn.ca

    DocumentRoot "E:/web/intra/htdocs"
    ServerAdmin  admin@domain.ca

    ...
</VirtualHost>

Edit #1

This seems to work thus far...

RedirectMatch (.*) intra-beta.domain.ca$1

Edit #2

How about a situation like this:

<VirtualHost _default_:443>
#   General setup for the virtual host
DocumentRoot "E:/web/inter-ssl/htdocs"
ServerName   inter-dev.domain.ca:443
ServerAdmin  admin@domain.ca

...
</VirtualHost>

If I do the modifications so that it looks like this:

<VirtualHost *:443>
    ServerName inter-dev
    RedirectMatch (.*) inter-dev.domain.ca$1
</VirtualHost>

<VirtualHost _default_:443>
    #   General setup for the virtual host
    DocumentRoot "E:/web/inter-ssl/htdocs"
    ServerName   inter-dev.domain.ca:443
    ServerAdmin  admin@domain.ca

    ...
 </VirtualHost>

I get an error related with too many redirects. If I understand correctly, SSL works differently and this fix might not be a correct implementation in this situation?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

You need to explicitly configure your redirect:

<VirtualHost *:80>
  ServerName intra-beta
  RedirectMatch /.* http://intra-beta.domain.ca
</VirtualHost>

In your case, every request whose Host: header doesn't match any of the configured ServerNames will be answered by the first VirtualHost whose IP address matches. Thus, if you put the above new VirtualHost at the first position in your configuration file, all requests whose Host: header is different from intra-beta.domain.ca, intra.otherDomainFr.ca or intra.otherDomainEn.ca will be redirected to http://intra-beta.domain.ca.

share|improve this answer
    
I might be getting greedy here, but is it possible to append the original querystring/path to the redirect? –  TekiusFanatikus Jul 26 '12 at 14:55
    
Don't you get that in the Referrer? –  Oliver Jul 26 '12 at 14:57
    
this seems to work thus far RedirectMatch (.*) intra-beta.domain.ca$1 –  TekiusFanatikus Jul 26 '12 at 15:41
    
seems that applying this solution to ssl (or port 443) doesn't work. See Edit #2 –  TekiusFanatikus Jul 26 '12 at 16:11

in /etc/hosts you got an entry

127.0.0.1   machine   machine.domain.com

or you have configured dns to assume local domain for each hostname and it is trying to resolve hostname with this local domain each time a hostname is in DNS query.

share|improve this answer
    
You cannot "configure DNS" to do that; it is a function of the machine 's local resolver library. –  adaptr Jul 26 '12 at 16:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.