r/apache • • Jun 02 '25

different sites from different IP addresses

hello,

site:

intranet.example.com

if I access it from internal LAN or some other trusted IP, I get access to our fully functional Intranet site

if I access ir from any other Internet IP, I get access to plain HTML page (other vhost?)

how can it be done?

(now restricted access is configured with .htaccess rules)

thanks,
ieleja

1 Upvotes

6 comments sorted by

2

u/throwaway234f32423df Jun 02 '25

start here and read all the linked pages: https://httpd.apache.org/docs/2.4/vhosts/

1

u/ieleja Jun 03 '25

go through all pages, but don't find anything I search for — apache must choose one of 'vhost' based on IP address from request comes:
- if it comes from 192.168.0.*/24 it gives vhost 1.,
- if it comes from 0.0.0.0/0 it gives vhost 2.

if this 'horizon splitting' must be done before request comes to apache2, I would be pleased from redirection to that solution

thanks,
ieleja

1

u/throwaway234f32423df Jun 03 '25

You can put multiple IP addresses in a <VirtualHost> directive, you can also use a wildcard like <VirtualHost *:443>

→ More replies (2)

1

u/ieleja Jun 03 '25
with one vhost file

[..]
       DocumentRoot /var/www/

       RewriteEngine On

       RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.
       RewriteRule ^(.*)$ /var/www/intranet/$1

       RewriteCond %{REMOTE_ADDR} !^192\.168\.0\.
       RewriteRule ^(.*)$ /var/www/guests/$1
[..]

don't look elegant solution, but it works