PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 22, 2022

[FIXED] How to deny access to the host by domain name?

 September 22, 2022     .htaccess, apache, virtualhost     No comments   

Issue

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


Solution

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.



Answered By - Jon Lin
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing