Forum

Regular expression problems when using a reverse proxy

Boone
9 July 2018, 23:00
I'm using Hiawatha's reverse proxy functionality to forward requests to multiple servers. However, it seems that Hiawatha is having trouble handling some forms of regular expression as I get syntax errors. I used regex101.com to verify my regular expressions, and the results can be seen here: https://regex101.com/r/JON5YU/2 . However, Hiawatha gives me a syntax error when using this regular expression. Are there some regular expressions that Hiawatha cannot handle or is there a different way I should be handling this? Relevant VirtualHost below:
VirtualHost{
Hostname=127.0.0.1
WebsiteRoot = /path/to/website
StartFile =index.html
AccessLogfile = /path/to/access.log
ErrorLogfile = /path/to/error.log
ReverseProxy ^(?!\/foo).*$ http://localhost:3000/ #should redirect everything that doesn't start with /foo. Syntax error apparently here
ReverseProxy ./foo* http://127.0.0.1:3011/ #should redirect everything that starts with /foo
}
Hugo Leisink
10 July 2018, 15:04
Could it be the multiple spaces (or tab?) behind the regular expression?
Boone
10 July 2018, 18:50
I've tried removing the spaces along with a host of other things. It doesn't seem to make any difference. There's always a syntax error
Hugo Leisink
10 July 2018, 18:53
What is the regexp supposed to do?
Boone
10 July 2018, 19:05
Goal is indicated by comments in the code above. I want the first to redirect everything that does not start with /foo, and the second to redirect everything that does start with /foo
Boone
10 July 2018, 19:08
Just clarifying because I have since discovered this, the second ReverseProxy has an error. The regexp should be ^\/foo*. Regardless, I'm gettting a syntax error on the first ReverseProxy, not the second
Boone
10 July 2018, 20:16
After searching through the forums again, I managed to find this post: https://www.hiawatha-webserver.org/forum/topic/2719/#13257 indicating that Hiawatha is incapable of parsing some regular expressions. I would like to add a +1 to the request to implement a more robust regex library. For the current time, it looks like I'll have to try something else to get a workaround.
Thanks for all your help Hugo!!
Hugo Leisink
10 July 2018, 21:43
Ah, missed the comment lines. Well, I think it's easier than you might think. How about this:
ReverseProxy ^/foo.* http://127.0.0.1:3011/ # Redirect everything that starts with /foo.
ReverseProxy .* http://localhost:3000/ # Redirect everything that doesn't start with /foo, because of previous line.
Boone
12 July 2018, 02:18
You're correct there. I didn't realize that ordering could make a difference. Thanks Hugo!!
This topic has been closed.