: Apache Virtual Host different depending on client ip? What I'm trying to accomplish is: 1. A person, with IP 192.168.1.5 loads my webserver (192.168.1.2) and reaches htdocs/ 2. Another person,
What I'm trying to accomplish is:
1. A person, with IP 192.168.1.5 loads my webserver (192.168.1.2) and reaches htdocs/
2. Another person, with ip 192.168.1.6 does the same request, and reaches htdocs/folder/
If possible, I'd like to stick to port 80 requests only.
I'm currently using the setup:
<LocationMatch "/">
Order deny,allow
Deny from all
Allow from ::1 127.0.0.0/8 localhost 192.168.1.5
ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
</LocationMatch>
<VirtualHost 192.168.1.2:80>
ServerAdmin frederik@*.dk
DocumentRoot "/XAMPP/htdocs/"
ServerName 192.168.1.2
ErrorLog "logs/lan-error.log"
CustomLog "logs/lan-access.log" combined
</VirtualHost>
I'd like to allow everyone else to see the folder. And then, depending on the client IP, set another DocumentRoot.
More posts by @Sue5673885
1 Comments
Sorted by latest first Latest Oldest Best
I don't think you can do it the way you're envisioning (with conditional DocumentRoot). However, you can achieve the same thing with Apache Rewrites by adding the following to your VirutalHost declaration, or in the .htaccess file in your document root:
RewriteEngine On
RewriteCond %{REMOTE_HOST} !^192.168.1.5
RewriteCond %{REQUEST_URI} !^/blog/?
RewriteCond %{REQUEST_URI} /(.*)$
RewriteRule (.*) /blog [R=301,L]
Essentially, if the user's IP isn't your IP address, and they're not requesting something in the /blog folder, it will redirect them to the /blog folder. If it's your IP address, or if they're requesting something in the /blog folder, then no redirect will occur.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.