6

I don't know if this could be possible on apache yet, I've done hefty amount of research before coming here. but:

I have a VirtualHost running at **:80*, ServerName to somedomain.tld. What I want to achieve is if client 10.2.1.4 accesses somedomain.tld, the client will be served content from DocumentRoot /var/www/pages-1/. Then if 10.3.0.* accesses the same somedomain.tld, the client will get content from DocumentRoot /var/www/pages-2/. Is there any way to achieve this currently?

Bart De Vos
  • 17,761
  • 6
  • 62
  • 81

2 Answers2

7

You can do this with a RewriteRule preceded by a RewriteCond that checks the remote_addr (remember using % for the vars, not $:

<VirtualHost *:80>
  Servername somedomain.tld

  RewriteEngine On
  RewriteCond %{REMOTE_ADDR} 10.2.1.4
  RewriteRule ^(.*)$ /var/www/pages-1/$1

  RewriteCond %{REMOTE_ADDR} 10.3.0.
  RewriteRule ^(.*)$ /var/www/pages-2/$1

</VirtualHost>
aseques
  • 688
  • 4
  • 12
  • 26
adaptr
  • 16,479
  • 21
  • 33
3

It won't be possible to change the document root, but you can rewrite the URL based on the client IP, something like...(not tested)...

RewriteCond %{REMOTE_HOST} ^10\.3\.0\.
RewriteRule ^/(.*) /pages-2/$1 [P,L]

RewriteCond %{REMOTE_HOST} ^10\.2\.1\.4$
RewriteRule ^/(.*) /pages-1/$1 [P,L]

Although it might be simpler to use an external rewriting program if the number of IP addresses is very large.

symcbean
  • 19,931
  • 1
  • 29
  • 49