Forum Discussion
URI Rewrite
HI All,
I have a specific requirement to rewrite the URI when the user requests the URL and the change has to be made interanlly without knowing to the external user.
Original URL : https://www.abc.com/customer/context/html need to be changed internally as below
https://abc.com/testcustomer/testcontext/html
Can anyone help me by providing an iRule matching the above.
Thanks in advance.
14 Replies
- Kevin_Stewart
Employee
Silently changing the URI on the inbound request is best done with the HTTP::uri command.
ex. HTTP::uri "/testcustomer/testcontext/html"
The browser won't see this.
The next question is if you mean to literally change "customer" to "testcustomer" and "context" to "textcontext", or really want to dynamically add "test" to the front of each path layer (and not touch the last path field)? - silver
Nimbostratus
Basically i need as below.
Customer --- > https://abc.com/testcustomer/testcontext/html need to internally rewritten as https://abc.com/customer/context/html.
So the external users should not see the changes happening internally.
Can you please help by providing an irule satisfying the above condition. - Kevin_Stewart
Employee
Well, very simply:
if { [string tolower [HTTP::uri] equals "/testcustomer/testcontext/html" } {
HTTP::uri "/customer/context/html"
}
That'll literally change "testcustomer" to "customer" and "testcontext" to "context". - silver
Nimbostratus
I had updated as below but not working.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/testcustomer/testcontext/html"] } {
HTTP::uri "/customer/context/html"
}
}
When checking the log it shows the connection is closed.
Anyone plz help - Michael_Yates
Nimbostratus
Hi Silver,
You have an extra "]" in your iRule.
Try this:when HTTP_REQUEST { if { [string tolower [HTTP::uri]] equals "/testcustomer/testcontext/html" } { HTTP::uri "/customer/context/html" } }
If you are not using it I would suggest using the iRule Editor. It can help you with IntelliSense for iRule TCL Commands and syntax checking. You can find the download link on the home page of DevCentral.
Hope this helps. - silver
Nimbostratus
Hi Mike,
The connection is getting closed for the request after applying the iRule and not able to get any pages.
Basically the Context path has to be changed internally and need to send to the Server and this should not be known to the external users.
Your great ideas/solution will help me to achieve the above req. - What_Lies_Bene1
Cirrostratus
Could you do a tcpdump and see what the server response contains? Does it look normal? What exactly do you mean by the connection is getting closed, can you be more specific? - nathe
Cirrocumulus
I'd try fiddler / httpfox and see if that gives any more info. Also, you could try Curl as well on the ltm box to see what errors are returned e.g.
curl -I http://x.x.x.x/customer/context/html
See if that helps,
N - nathe
Cirrocumulus
Apologies -
curl -I http://x.x.x.x/testcustomer/testcontext/htm
N - Michael_Yates
Nimbostratus
Hi silver,
Sorry to hear that it isn't working for you. Let's try this.
What is the location the user is going to request?
http://www.website.com/testcustomer/testcontext.html
or
http://www.website.com/testcustomer/testcontext/html/index.html
Then what do you want them to be changed to?
http://www.website.com/hiddendir1/hiddendir2/testcontext.html
or
http://www.website.com/hiddendir1/hiddendir2/html/testcontext.html
I would suggest only trying to manipulate the directory structure by injecting or removing parts of the path. If you try a full on web PAGE hide then things are going to get ugly in a hurry (becuase you have to account for the directory structure of the target page and all directory strutures that page depends on to pull content like Images, CSS Files, etc.)
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com