Forum Discussion
Rewrite Portion of URI
We are moving one of our web services to a new pool of servers which will contain a different virtual directory structure. The legacy servers used a separate virtual directory for each customer, but the new servers will utilize a common virtual directory. We do not want the customers making any changes and have been asked if we can perform the rewrite.
The legacy request looks something like this... https://www.mysite-old.com/CUST_A/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN
The new request will need to be rewritten like this... https://www.mysite-new.com/app.web/APPvirtualDirectory/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN
/CUST_A/ will need to be rewritten with /app.web/APPvirtualDirectory/ but everything after will need to be retained. Also, the legacy server virtual directory names can be any length so I will not be able to replace a fixed number of characters.
Any help would be greatly appreciated.
6 Replies
- Eric_Frankenfie
Nimbostratus
This is what I have tried so far
when HTTP_REQUEST { HTTP::uri [string map {"/*/Login.aspx?" "/app.web/APPvirtualDirectory/Login.aspx?"} [HTTP::uri]] } - nitass
Employee
e.g.
config root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar ltm virtual bar { destination 172.28.24.10:80 ip-protocol tcp mask 255.255.255.255 pool foo profiles { http { } tcp { } } rules { myrule } source 0.0.0.0/0 source-address-translation { type automap } vs-index 14 } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo ltm pool foo { members { 200.200.200.101:80 { address 200.200.200.101 } } } root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule myrule ltm rule myrule { when HTTP_REQUEST { if { [HTTP::uri] starts_with "/CUST_A/" } { HTTP::uri [string map {/CUST_A/ /app.web/APPvirtualDirectory/} [HTTP::uri]] } HTTP::header replace Host "www.mysite-new.com" } } test [root@ve11a:Active:In Sync] config ssldump -Aed -nni 0.0 port 80 New TCP connection 1: 172.28.24.1(39115) <-> 172.28.24.10(80) 1393145648.5634 (0.0029) C>S --------------------------------------------------------------- HEAD /CUST_A/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Accept: */* Host: www.mysite-old.com --------------------------------------------------------------- New TCP connection 2: 200.200.200.14(39115) <-> 200.200.200.101(80) 1393145648.5958 (0.0298) C>S --------------------------------------------------------------- HEAD /app.web/APPvirtualDirectory/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN HTTP/1.1 User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5 Accept: */* Host: www.mysite-new.com --------------------------------------------------------------- - Eric_Frankenfie
Nimbostratus
The issue I have is there are 100+ different virtual directories on the legacy web server and I don't currently have a complete list.
Is there a way to replace everything between / and / of the legacy URI with /app.web/APPvirtualDirectory/
For example...
/CUST_A/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN becomes /app.web/APPvirtualDirectory/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN and /CUST_ZZZ/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN becomes /app.web/APPvirtualDirectory/Login.aspx?C=98620001&UN=COMS8365&PW=av99er89uj&F=EN ... ... ... - Eric_Frankenfie
Nimbostratus
I finally received the list of virtual directories from the development team.
This is what I ultimately used...
Create a new string Data Group containing the legacy URI
ltm data-group legacy_uri records { /custa/ /custb/ /custc/ ...iRule
when HTTP_REQUEST if { [class match [string tolower [HTTP::uri]] starts_with legacy_uri]} { set uri_leg [class match -name -- [string tolower [HTTP::uri]] starts_with legacy_uri] set uri_new "/app.web/APPvirtualDirectory/" HTTP::uri [string map [list $uri_leg $uri_new] [string tolower [HTTP::uri]]] } } - Eric_Frankenfie
Nimbostratus
Is this the best way to go about this or is there a more efficient method?
- JG
Cumulonimbus
This can be fixed with some URL rewrite rules on most Web servers at the backend, where this should be done.
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