Sign up ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

i have a linux mail+http server located throguh Internet at Domain was bought at GoDaddy so after configuring the server and getting the public ip address i went at GoDaddy's profile to modify the A and MXentries for my dns zone in order to point them to my server's public ip address. In the MX entry i did not placed the ip address but an alias called

Everything works fine but, as and both are pointing to x.y.w.z where i have apache running, when you write or either in the Internet Browser my default web page is shown. I would like to tell apache to only show the page if is written in the url and deny the access if is written. Does anyone knows how sould i do it? Thanks :)

NameVirtualHost *:80

<VirtualHost *:80>
  DocumentRoot /var/www/html/
  ErrorLog logs/mydomain_com-error_log
  CustomLog logs/mydomain_com-access_log common
share|improve this question

migrated from Sep 14 '11 at 18:37

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 2 down vote accepted

Just create another virtual host for, and you can tell Apache to do whatever you want when people go to that host.

<VirtualHost *:80>
    ErrorLog logs/example_com-error_log
    # if you care about hits:
    CustomLog logs/example_com-access_log common

Then, if you want to forbid access entirely:

    <Directory />
        Order allow,deny
        Deny from all

Or to redirect to your real domain do this instead:

    RedirectPermanent /

Or you could do something else.

share|improve this answer
Thanks a lot for the tips :) – user846226 Sep 16 '11 at 8:55

If you put the following into your .htaccess every visitor coming to your site by means of any domain other than will be forcedly redirected to the right domain:

RewriteEngine On
RewriteCond %{HTTP_HOST}   !^www\.example\.com$ [NC]
RewriteRule ^(.*)$1 [L,R=301]
share|improve this answer
Thx a lot for the answer. Is it possible to achieve what i asked for just through a proper virtualhost configuration set? – user846226 Sep 14 '11 at 17:32
Although technically this works, it's inefficient for a couple reasons: first, mod_rewrite is pretty complex so it's best to avoid using it when you can do without it; also, enabling .htaccess files at all adds several filesystem accesses to every request. Besides, it's just weird organization to put a domain-level redirect in a directory context. – David Z Sep 14 '11 at 20:31
@David, all you say is true, unless you're on a shared hosting where you either way have .htaccess enabled. – sanmai Sep 15 '11 at 9:43

Your Answer


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.