: Redirect public traffic to a different subfolder, while local traffic remains unchanged I would like to have local (intranet) HTTP traffic go to the /var/www/html folder while any public traffic
I would like to have local (intranet) HTTP traffic go to the /var/www/html folder while any public traffic goes to the subfolder, /var/www/html/public
I've tried this configuration, with some variation, in httpd.conf
<VirtualHost PRIVATE-IP>
DocumentRoot /var/www/html
ServerName ecn
ErrorLog /var/www/logs/error/private
CustomLog /var/www/logs/access/private common
</VirtualHost>
<VirtualHost PUBLIC-IP>
DocumentRoot /var/www/html/public
ServerName PUBLIC-DOMAIN-NAME
ErrorLog /var/www/logs/error/public
CustomLog /var/www/logs/access/public common
</VirtualHost>
PUBLIC-IP, PRIVATE-IP, and PUBLIC-DOMAIN name are all replaced with the correct values in the actual document.
The problem is, local traffic can browse fine but remote traffic is directed to the root folder and getting 403d (because I have that folder blocked off through my .htaccess file). If I append /public to the URL it works fine.
More posts by @Hamm4606531
2 Comments
Sorted by latest first Latest Oldest Best
Check that you are using NameVirtualHost directive for each IP address. From the documentation, that is required.
Your first Virtual host is the "default" virtual host. I think that your public virtual host isn't actually matching anything and is getting caught in the first "default" virtual host. I would create a "dummy" virtual host that goes first. Try this:
Listen 80
# public
NameVirtualHost 11.22.33.44:80
# private
NameVirtualHost 192.268.0.1:80
<VirtualHost _default_:*>
# Default virtual host configuration
DocumentRoot /var/www/html/default
ServerName default
ErrorLog /var/www/logs/error/default
CustomLog /var/www/logs/access/default common
</VirtualHost>
<VirtualHost 192.168.0.1:80>
DocumentRoot /var/www/html
ServerName ecn
ErrorLog /var/www/logs/error/private
CustomLog /var/www/logs/access/private common
</VirtualHost>
<VirtualHost 11.22.33.44:80>
DocumentRoot /var/www/html/public
ServerName example.com ErrorLog /var/www/logs/error/public
CustomLog /var/www/logs/access/public common
</VirtualHost>
I am not aware of the solution you are using but it does look solid from here. Clearly I have something new to learn.
I do redirects depending upon IP addresses in .htaccess. I thought I would provide an example if it helps.
RewriteCond %{REMOTE_ADDR} "!^120.0.0.([0-255])$"
RewriteRule mydomain.com/public [R,L]
If this is not right, perhaps it is enough to get you there. You can use it in the httpd.conf or .htaccess files and modify it to your purposes. If your private IP address is not this simple, let me know. I have more complex examples.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.