Edward Komissarov
Edward Komissarov

Reputation: 83

How to deny access to the host by domain name?

How I can to implement next logic in the virtualhost config :

<VirtualHost *:80>

    ServerName domain.com
    ServerAlias admin.domain.com

    DocumentRoot /usr/.../www

    <Directory /usr/.../www>

        AllowOverride all

        if (%{HTTP_HOST} == 'admin.domain.com') {
            deny from {some ip}
        }

    </Directory>

</VirtualHost>

I need to make admin.explample.com acceseble only from specific IP

Upvotes: 2

Views: 108

Answers (1)

Jon Lin
Jon Lin

Reputation: 143906

Replace:

    if (%{HTTP_HOST} == 'admin.domain.com') {
        deny from {some ip}
    }

with

RewriteEngine On
RewriteCond %{HTTP_HOST} ^admin\.domain\.com$ [NC]
RewriteCond %{REMOTE_ADDR} !^12\.34\.56\.78$
RewriteRule ^ - [L,F]

where 12.34.56.78 is the IP that you want to be able to access the host. All other IPs will cause a 403 Forbidden result.

Upvotes: 1

Related Questions