I don't understand you problem. The goal of the rewriting is to prefix website urls with the address of the gateway.
Sorry, maybe I write more details. The original URL is like that
root directory: originalPage, targetPage
Do you have any idea about it, or if you need, i can post my program