Mobile app version of vmapp.org
Login or Join
Shakeerah822

: Apache2: Deny access for mail.mydomain.com but allow www.mydomain.com, both points same ip i have a linux mail+http server located throguh Internet at www.mydomain.com. Domain was bought at GoDaddy

@Shakeerah822

Posted in: #Apache #HttpdConf #MultipleDomains #Virtualhost

i have a linux mail+http server located throguh Internet at mydomain.com. 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 mail.mydomain.com.

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

NameVirtualHost *:80

<VirtualHost *:80>
ServerAdmin admin@mydomain.com
DocumentRoot /var/www/html/mydomain.com/
ServerName mydomain.com ErrorLog logs/mydomain_com-error_log
CustomLog logs/mydomain_com-access_log common
</VirtualHost>

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Shakeerah822

2 Comments

Sorted by latest first Latest Oldest Best

 

@Odierno851

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

<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName mail.example.com
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
</Directory>


Or to redirect to your real domain do this instead:

RedirectPermanent / www.example.com/

Or you could do something else.

</VirtualHost>

10% popularity Vote Up Vote Down


 

@Heady270

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

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*) www.example.com/ [L,R=301]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme