Jump to content

How do i change Title with a rewrite responder action?


Recommended Posts

How do i change "<title>Fun Page</title>" with a rewrite responder action?
Looks like i'm unable to figure this out.
 

 

This doesn't work, since this only looks in "body"
add rewrite action rw_act_fun_page replace_all "HTTP.RES.BODY(1024)" "\"Test page\"" -search "text(\"fun page\")"
add rewrite policy rw_pol_fun_page true rw_act_fun_page

 

Example HTML-code in webbrowser:
<!DOCTYPE html>
<html>
      <head>
              <title>Fun Page</title>
                  <style>
      body {
                  background-color: red;
                    }
          </style>
        </head>
          <body>
                  <h1 style="color: white; text-align: center;">Welcome to my Test page!</h1>
                  <p style="color: white; text-align: center;">I hope you enjoy the red background.</p>
                      <img src="/freebsd_logo-full.png" alt="animated fun image" style="display: block; margin: 0 auto;">
                    </body>
</html>

 

I just want to be able to easley manipulate the "Title"

 

Kind Regards,

Edited by Nicklas Ryden
Link to comment
Share on other sites

HTTP.RES.BODY(1024) refers to the first 1024 bytes of the payload in the message.  Therefore all parts of the HTML message are included, including the title.  1024 bytes (ie characters) processes up to just after the first style tag.  HTTP.RES.BODY(HTTP.RES.CONTENT_LENGTH) would be all of the body, dynamically updated.

Check to make sure you are getting policy hits when you request the page.   

1) Check the configured Rewrite policy Expression is correct using the Expression Evaluator.  In your case TRUE will always hit.  

2) Bind the policy to the right Vserver (Load balancing or Content Switching or NetScaler Gateway Vserver).

3) Verify the Rewrite is bound in the correct direction (Request vs Response).

4) If more than one Rewrite policy is bound under Vserver with the expression as "ns_true" or "TRUE" verify if the GOTO EXPRESSION is set to NEXT instead of END.

 

If you are getting hits, but not getting the rewrite, beware of browser and NetScaler Caching. 

1) Use private browsing mode in your browser to ensure your browser will not use cached content which does not pass through the NetScaler.   

2)  You can clear the on the NetScaler from the shell (nsapimgr_wr.sh -ys call=ns_ic_flush) but you can also allocate zero memory to the integrated caching module to disable it.  (though if it's not enabled it only be caching for the gateway module) 

3) Run a trace or packet capture at the server to make sure it is sending the complete response rather than acknowledging cached data. 

4) Rewrite can also be used to remove via caching headers.  

 

  • Like 1
Link to comment
Share on other sites

Hi Rick,

Thank you for clearing HTTP.RES.BODY(1024).

I solved is by being more specific :)

add rewrite action rw_act_fun_page replace_all "HTTP.RES.BODY(1024)" "\"<title>sad3 page</title>\"" -search "text(\"<title>Fun Page</title>\")"
add rewrite policy rw_pol_fun_page true rw_act_fun_page

 

This worked just fine :)

Cheers!

/n

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...