User-Agent based redirect in haproxy
Saturday, March 19, 2016
How To Do User-Agent based redirect in haproxy :-
below are the steps:-
1) Create new ACL to identifiy user-agent:
acl mobile_user_agent hdr_sub(User-Agent) -i iphone
2) We didn't want to redirect any requests for .css, .js, .bmp, .jpg, .png, .jpeg, .gif and .ico so created a new ACL
acl is_static_file url_reg .*\.(css|js)\?[0-9.]+
acl is_static_img url_reg .*\.(png|bmp|jpg|jpeg|gif|ico)\?[0-9a-z.]+
acl is_static url_reg .*\.(css|js|png|bmp|jpg|jpeg|gif|ico)
3) If request was for /mobile/* we didn't want to redirect so yet another ACL :)
acl is_mobile url_reg ^\/mobile.*
4) Do a URL rewrite as follows:
reqrep ^([^\ ]*)\ /(.*) \1\ /mobile/\2 if iphone !is_static_file !is_static_img !is_static !is_mobile
So now any request coming from a mobile device for any thing other than .css, .js, .png, .gif, .bmp, .jpg, .jpeg, ico will be redirected to /mobile/.
So a request like www.example.com/pqr will become www.example.com/mobile/pqr !
0 comments:
Post a Comment