Author Topic: Rewrite Body Links  (Read 3426 times)

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Rewrite Body Links
« on: January 13, 2009, 09:34:10 AM »
We are bringing a beta site online and I am looking to write the static links on the pages to the beta site which also has the content.

For example:

if a user goes to test.site.com/beta_site and clicks a link on the page the link will take them to test.site.com/site I need to rewrite that link to beta_site.

I have tried using a rewrite option going from

add rewrite action sitetobeta replace_all "http.req.body(5000)" "\"beta_site\"" -pattern site
add rewrite policy sitetobetaPolicy "http.req.url(5000).contains(\"beta_site\")" SitetoBetaI


I tried a few variants of this with no success. Can anyone lend a hand?

Thanks.

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #1 on: January 14, 2009, 11:06:57 AM »
There are many things you will have to rewrite, being the links just one of them. Normally the response will have links in the form /path or //path, if the app was developed with links in the form http://site/path then your developers did a ver poor job.
On the other hand you have to ber carefull with the Host header, since most implementations of application containers will use this header to select the site to be displayed.
I have found that Oracle Application Server uses the hostname of the maquine to build a META tag that informs the client browser that the links need to be build in a specific way, you have to look for that to.
As you can see it is not a trivial thing to do, if you are looking into rewriting a link or two, rewrite is the best solutions.
But first try to solve things inside the application, then when you can proceed no further, look for solutions from the netscaler.

If you need help with specific rewrite policies and actions, I will gladly help you.

Daniel

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #2 on: January 14, 2009, 02:05:28 PM »
There are many things you will have to rewrite, being the links just one of them. Normally the response will have links in the form /path or //path, if the app was developed with links in the form http://site/path then your developers did a ver poor job.
On the other hand you have to ber carefull with the Host header, since most implementations of application containers will use this header to select the site to be displayed.
I have found that Oracle Application Server uses the hostname of the maquine to build a META tag that informs the client browser that the links need to be build in a specific way, you have to look for that to.
As you can see it is not a trivial thing to do, if you are looking into rewriting a link or two, rewrite is the best solutions.
But first try to solve things inside the application, then when you can proceed no further, look for solutions from the netscaler.

If you need help with specific rewrite policies and actions, I will gladly help you.

Daniel


Daniel, Thank for getting back to me.  All the Links are in the form of /path or //path. Basically I want to change the paths when they are clicked to go from  /path/test.asp to /beta_path/test.asp.  I can't get the rewrite functions to even recognize the pattern when the link is clicked. I am wondering if i am using the wrong policy to call the action.

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #3 on: January 14, 2009, 06:39:05 PM »
test this fisrt:
add rewrite action test insert_http_header Daniel HTTP.RES.DATE.SECONDS
add rewrite policy daniel_test "HTTP.RES.HEADER(\"Content-Type\").CONTAINS(\"html\")" test

This policy will insert a Header called Daniel with the value of the second that the response passed the NS. This will allow us to know if rewrite is working fine or we have to do some more stuff to make it work.
If the Header is inserted correctly then we will proceed with the URL rewrite.
Daniel

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #4 on: January 15, 2009, 05:50:27 AM »
Daniel, Using your rewrite actions, when I load a page I am seeing a Response Header of "Daniel" with a value of the seconds. Seems to be working.

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #5 on: January 17, 2009, 07:48:15 AM »
OK, can you post the action and policy you are using for your rewrite?

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #6 on: January 26, 2009, 10:18:54 AM »
Hey Daniel, Sorry for the delay.

For the rewrite action I am using:

 add rewrite action clear_string REPLACE 'HTTP.REQ.URL.PATH.GET("site/")' '"site/beta"'
 
and for the policy temporarily i am using just to keep it open

add rewrite policy clear_string_pol1 'HTTP.REQ.HOSTNAME.CONTAINS("site.com")' clear_string

This is working but only for the home page E.G. going to www.site.com/site rewrites you and the home page links to www.site.con/site/beta but once I click a link on the second page it doesn't.

The links look the same no difference and they are coded the same. I am not sure whats going on there.

Thanks again.

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #7 on: January 26, 2009, 11:35:20 AM »
Ok,
First include on the policy && REQ.HTTP.Header("Content-Type") contains "html"

No I you run a fiddler trace to se how is the http traffic coming and going, we need to understand how you application really works.
For example when you click on a link you are really going to the server and he responds with a redirect, and when you get the page you are getting lost somewhere...

Daniel

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #8 on: January 26, 2009, 12:54:41 PM »
I'm using firebug and httpfox to view the requests and response's. I am not seeing any redirects.

Could this be the problem?

It looks like my rule is only working when the replace is at the end of the url. for example.


When i go to www.site.com/site the rewrite rule works and rewrites the url to www.site.com/site/beta/

but

if I go to a link that has www.site/site/pro/articles/article.asp it will never rewrite site to site/beta in the url.

Am i missing something in the action policy to handle when the value is in the middle of the URL instead of the end?

Thanks.

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #9 on: January 26, 2009, 04:49:04 PM »
I was misreading your action, you are trying to rewrite the URL from the GET, not rewrite the entire content of the body.
I will make a small lab for this and get back to you.

Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #10 on: January 27, 2009, 09:48:03 AM »
Thanks Daniel. I appreciate your help.


Offline Econ

  • Sr. Member
  • **
  • Posts: 14
  • Karma: 0
Re: Rewrite Body Links
« Reply #11 on: January 29, 2009, 06:41:13 AM »
If I attempt to use a Contains instead of the GET it will not allow me to associate the rewrite rule to the LBVS.

Example: HTTP.REQ.URL.PATH.CONTAINS("site/")

I am assuming that is not possible?

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #12 on: January 29, 2009, 07:54:09 AM »
I have never tryed to rewrite the GET url on the request, I have rewrited the body looking for liks and it works like a charm most of the time.

Daniel

Offline evildani

  • Administrator
  • Hero Member
  • *****
  • Posts: 373
  • Karma: 22
Re: Rewrite Body Links
« Reply #13 on: January 31, 2009, 07:10:33 AM »
Sorry it took me so long, here it is, I test it and it works like a charm:

add rewrite action replace_url replace_all http.REq.URL.PATH.TYPECAST_HTTP_URL_T "\"site/beta/\"" -pattern "re~site/~"
add rewrite policy daniel "HTTP.REq.url.HTTP_URL_SAFE.CONTAINS(\"site/\")" replace_url
bind rewrite global daniel 90 END -type REQ_OVERRIDE

One side note, you have to be carefull with the cache, since the rewrite is done after the cache hit.

Hope this helps.

Daniel

Offline jmelika

  • Administrator
  • Hero Member
  • *****
  • Posts: 339
  • Karma: 7
Re: Rewrite Body Links
« Reply #14 on: February 01, 2009, 09:50:09 AM »
Dani!  As always, your input blows me away.

This is golden.  Could you repost to the Tips & Tricks category?

Thanks!