I am trying to redirecto to other machine by filtering the user agent in a apache web server. I have a web server in the machine with the ip 192.168.2.11, but this web server only should send the page to the requests WITHOUT this user agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20
Instead it should redirect the request to 192.168.1.40 that have other web server running.
I tried to modify the file /etc/apache2/apache2.conf with the next code
RewriteEngine on
RewriteCond ${HTTP_USER_AGENT} "!=Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:99.0) Gecko/20"
RewriteRule ^(.*)$ https://192.168.1.40 [L,R=302]
But doesn't work, it always show index.html from the 192.168.2.11 machine (it doesnt redirect). Why? How can I do that?
EDIT
I think I'm indicating wrong the user_agent because this works fine:
RewriteEngine on
RewriteCond ${HTTP_USER_AGENT} Ubuntu
RewriteRule ^(.*)$ - [R=403,L]
So the question is, how can I specify a particular user_agent? and how can I spacify all user_agent exept that particular user_agent?
RewriteRule ^(.*)$ https://192.168.1.40/$1 [L,R=302]
This may not solve the entire issue as the redirect is still not working!, but this is required./etc/apache2/sites-enabled/000-default.conf
, not in the main config file. This config worked for me. Beware of the default behaviour of your browser which may switch to https.