Forum Discussion
Rewrite the content in URI with a short URL
Hi Experts
I need assistance on shortening of URL as follows
If a web page with following Source URL is browsed , then a part of URI (highlighted in bold) should be converted to "en" (which is English language ) and output should be Masked URL as shown below .
Source URL : http://hostname/secureapp/connect/report_en/REP/XYZ
Masked URL : http://hostname/en/XYZ
Regards, Ankur
I am unable to update my original post. Here is an updated version.
If you simply want to mask URL's then apply a STREAM profile with the following iRule.
when HTTP_REQUEST { log local0. "..in HTTP_REQUEST" no replacement for requests STREAM::disable disable compression server side HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE { log local0. "...in HTTP_RESPONSE" only replace text content if {!([HTTP::header value Content-Type] contains "text")}{ return} set search "" foreach pair [class get myclass] { set search "$search@[lindex $pair 0]@[lindex $pair 1]@" } log local0. "String replace=$search" STREAM::expression $search STREAM::enable }
Then create a string data class myclass as follows...
Name Value /secureapp/connect/report_en/REP /en /peter /pan
And get the following output from a logs
Rule /Common/myrule : ...in HTTP_REQUEST Rule /Common/myrule : ...in HTTP_RESPONSE Rule /Common/myrule : search=@/secureapp/connect/report_en/REP@/en@@/peter@/pan@
And the resulting web page...
It works! /en /pan
- Kevin_Davies_40NacreousDo you want this masked URL to actually work when you click it? Or you just want to mask it.
- Kevin_Davies_40Nacreous
If you simply want to mask URL's then apply a STREAM profile with the following iRule.
when HTTP_RESPONSE { log local0. "...in HTTP_RESPONSE" set search "" foreach pair [class get myclass] { set search "$search@[lindex $pair 0]@[lindex $pair 1]@" } log local0. "search=$search" STREAM::expression $search STREAM::enable }
Then create a string data class myclass as follows...
Name Value /secureapp/connect/report_en/REP /en /peter /pan
And get the following output from a logs
Rule /Common/myrule : ...in HTTP_RESPONSE Rule /Common/myrule : search=@/secureapp/connect/report_en/REP@/en@@/peter@/pan@
And the resulting web page...
It works! /en /pan
- Kevin_Davies_40NacreousPlease see update version below
- Kevin_Davies_40Nacreous
I am unable to update my original post. Here is an updated version.
If you simply want to mask URL's then apply a STREAM profile with the following iRule.
when HTTP_REQUEST { log local0. "..in HTTP_REQUEST" no replacement for requests STREAM::disable disable compression server side HTTP::header remove "Accept-Encoding" } when HTTP_RESPONSE { log local0. "...in HTTP_RESPONSE" only replace text content if {!([HTTP::header value Content-Type] contains "text")}{ return} set search "" foreach pair [class get myclass] { set search "$search@[lindex $pair 0]@[lindex $pair 1]@" } log local0. "String replace=$search" STREAM::expression $search STREAM::enable }
Then create a string data class myclass as follows...
Name Value /secureapp/connect/report_en/REP /en /peter /pan
And get the following output from a logs
Rule /Common/myrule : ...in HTTP_REQUEST Rule /Common/myrule : ...in HTTP_RESPONSE Rule /Common/myrule : search=@/secureapp/connect/report_en/REP@/en@@/peter@/pan@
And the resulting web page...
It works! /en /pan
- Ankur_5273Nimbostratus
Hi Kevin,
Thanks for the response !! Though i am ok working with irules , however the above example is little tough for me to understand . Could you please explain me the logic behind the same . Also request to consider the below URLs in your example
Source URL : http://www.myweb.com/secureapp/connect/report_en/REP/XYZ
Masked URL : http://www.myweb.com/en/XYZ
Regards, Ankur
- Kevin_Davies_40Nacreous
The STREAM commands allow search and replace of data passing to and from the webserver. In this case I have enabled it only on the response coming back from the webserver... (STREAM::enable/disable). The stream expression is a sequence of search and replace pairs in the format @search@replace@. The foreach loop builds a stream expression from name and value pairs in the class myclass. We also turn off compression as most websites send data compressed although the user is never aware of this but we cannot process compressed data. Removing the Accept-Encoding header means the website will not compress the reply.
So any webpage with http://www.myweb.com/secureapp/connect/report_en/REP/XYZ on it will display http://www.myweb.com/en/XYZ instead.
- Kevin_Davies_40Nacreous
Is this what you want? Or is it when they click on http://www.myweb.com/en/XYZ they get the webpage at http://www.myweb.com/secureapp/connect/report_en/REP/XYZ instead?
If thats what you are after then thats rather simple.
when HTTP_REQUEST { log local0. "..in HTTP_REQUEST" if {[class match [HTTP::uri] equals myuri]} { HTTP::uri [class match -value [HTTP::uri] equals myuri] } }
Using class myuri
Name Value /en /secureapp/connect/report_en/REP/XYZ
- Ankur_5273Nimbostratus
Hi Kevin
Thanks for the detailed explanation !! Yes , the previous one is correct . I want any webpage with http://www.myweb.com/secureapp/connect/report_en/REP/XYZ to be displayed as http://www.myweb.com/en/XYZ in the users' browser . Also please note that whenever the URI is triggered in any other part of the web page (any other link present inside the webpage containing this URI ) , then also it should replace /secureapp/connect/report_en/REP/ with /en . I believe that iRule configuration you mentioned above would do that as well.
Also , do i need to simply apply this iRule to the Virtual Server OR apart from applying this iRule to VS , i have to create a separate Stream profile as well and then apply to the VS . I have not worked on Stream profile before and would like to know what needs to be filled in Source and Target part ?
Regards, Ankur
- Kevin_Davies_40Nacreous
The stream profile by default works in both directions. Only through iRules can you control when it is applied. I you have seen in the first example I do this.
You apply the iRule to the resources section of your virtual server and you must add a stream profile to have access to the STREAM iRule commands. You can use the system default stream profile and you do not need to fill out any fields in the profile itself. The STREAM::expression command in the iRule does that for you. You add the profile in the advanced view of your virtual server properties. Note the iRule will not apply unless there is a stream profile attached.
In the data class I specified name and value. Name is your Search and and value is what it will be replaced with.
- Ankur_5273Nimbostratus
Hi Kevin,
Thanks a lot !! I will add "system default stream profile" to VS and will add the said irule for the VS . Is there any way to test out via F5 CLI if it is working ?
Regards, Ankur
- Kevin_Davies_40NacreousIf any of the above posts have provided a solution to your issue, please indicate so by clicking the tick to the left of them. This gives feedback and recognition to the volunteers who responded to your issue.
- Kevin_Davies_40Nacreous
I just setup a webpage with the strings on it and called that webpage through a virtual with the iRule attached. There is no way to trigger logging event when STREAM actually replaces something.
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