Simple rewrite problem.

503 views
Skip to first unread message

Mikael Wallin

unread,
Jun 15, 2015, 10:06:48 AM6/15/15
to browserm...@googlegroups.com
I want to redirect a request to my local server.

My code is: (in java)

BrowserMobProxy server = new BrowserMobProxyServer();
server.rewriteUrl("host\.domain\.com\/path1\/path2\/path3","localhost:8000/test");

I was hoping that host.domain/path1/path2/path3 would redirect to my localhost port 8000.

It doesn't, where do I go wrong?

je...@outlook.com

unread,
Jun 15, 2015, 3:06:05 PM6/15/15
to browserm...@googlegroups.com
The rewrite rules match the entire request, including the scheme (http/https), so adding that may solve your problem. The javadoc for rewriteUrl gives some examples: https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-core/src/main/java/net/lightbody/bmp/BrowserMobProxy.java#L277

Another thing to note is that the \ character is the Java String escape character, so if you want to escape a '.' in a regex, you'll need to escape the '\' before the period, i.e. "host\\.domain\..com".

je...@outlook.com

unread,
Jun 15, 2015, 3:11:35 PM6/15/15
to browserm...@googlegroups.com
One other note -- I just noticed a defect in the way the rewrite URLs are matched in the LittleProxy implementation. For https requests, the scheme (https://) and domain (www.example.com) aren't matched. For http, it depends on how the browser or other client sends the URL.

I'll open a defect and see about getting this resolved for beta-2. In the meantime, try your scenario with the legacy ProxyServer class (instead of BrowserMobProxyServer) to see if that works for you. If not, hang tight and I'll try to get a fix to master quickly :)

-Jason

Mikael Wallin

unread,
Jun 22, 2015, 8:14:22 AM6/22/15
to browserm...@googlegroups.com
Thx for your reply. I will hang tight :)

je...@outlook.com

unread,
Jun 30, 2015, 1:06:56 AM6/30/15
to browserm...@googlegroups.com
This should now be fixed in master. Let me know if you still run into issues with the URL rewriting, and I'll try to get them fixed before the beta-2 release. Note that you should include the scheme and host/port ("http://somedomain.com/...") in the URL rewrite pattern. Also, I do want to point out that you can't rewrite HTTP requests into HTTPS requests or vice versa.

Vijay Kumar

unread,
Jun 1, 2017, 3:10:06 AM6/1/17
to BrowserMob Proxy
Hi,

Can I redirect https url to differernt https url using BMP?
I am not able to. 
Its urgent requirement or can you suggest any work around?
Reply all
Reply to author
Forward
0 new messages