Forum Discussion

frisco76_104868's avatar
frisco76_104868
Icon for Nimbostratus rankNimbostratus
Jul 10, 2009

rewrite URI is not rewriting

hi all, I'm performing a URI rewrite. I want the rewrite to do the following:

 

 

anybody that has URI "/company/xyz", rewrite the URI to "/xyz". So http://www.mycompany.com/company/xyz/home.htm to http://www.mycompany.com/xyz/home.htm.

 

 

I expect to see my URL in the web browser to be http://www.mycompany.com/xyz/home.htm but I get http://www.mycompany.com/company/xyz/home.htm in the URL with the correct web page. If I remove the rule, and try to connect to http://www.mycompany.com/company/xyz/home.htm- I get 404 error so I know the page doesn't exist at the URL.

 

 

Any ideas why the URI isn't being rewritten in the browser? (Although I get the correct web page). In my debug, I see the new URI being written so I know its doing the job.

 

 

 

Here is my code:

 

 
 when HTTP_REQUEST { 
  
  start debug 
 set testuri [HTTP::uri] 
 log local0.debug "> ****StartURI='$testuri'"; 
  end debug 
 if { [HTTP::uri] contains "/company/xyz" } { 
  set variables  
 set origUri [HTTP::uri] 
 set origString "/company/xyz"; 
 set newString "/xyz"; 
 regsub -all $origString $origUri $newString newUri 
  start debug 
 set testuri [HTTP::uri] 
 log local0.debug "> ****StartURI='$testuri'"; 
     log local0.debug "> ****EndNewURI='$newUri'"; 
  end debug 
  write the new URI to HTTP session 
 HTTP::uri $newUri 
 string replace  
 } 
  
 } 
 
  • This is because you're redefining the URI (via HTTP::uri $newUri) before sending it on to the server. It happens 'behind the scenes' and is effectively obfuscating your URI to the client, sort of like a context-specific proxypass directive would work in Apache. The client is none the wiser.

     

     

    To accomplish what you want, you may need to issue a redirect to your newly defined URI and add any code you may need to handle that new request in your rule.

     

     

    -Matt
  • Hi L4L7, thanks for the response. Hmm, I thought I had this working to rewrite the URI.

     

     

    I will look around and see if I can find an example of the redirect on the URI (i would think that is a common iRule syntax).

     

     

    seeya.
  • L4L7, Thanks for the example syntax, I appreciate it. I will try to implement this on Monday

     

     

    Have a good weekend!