Wednesday, January 21, 2015

virtualhost - Apache: Client-IP-based DocumentRoot



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?


Answer



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




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



No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...