Forum Discussion

Richie_66774's avatar
Richie_66774
Icon for Nimbostratus rankNimbostratus
Sep 15, 2009

Redirect a small URL to the real URL

I am trying to rewrite a request that I receive like this:

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] starts_with "/anything" } {

 

HTTP::uri "/default.aspx?=anything"

 

}

 

}

 

 

Except the "anything" needs to be a [uri::path] or something so when it changes all the time it will insert the parameter for the full URL Path.

3 Replies

  • Do you want to take the whole URI and set it as a parameter value? If so, you should URI encode the value:

     
     when HTTP_REQUEST { 
         Check if the URI set to lower case starts with /anything 
        if { [string tolower [HTTP::uri]] starts_with "/anything" } { 
      
            Rewrite the URI to /default.aspx with a new parameter and the value set to the URI encoded original URI 
           HTTP::uri "/default.aspx?original_uri=[URI::encode [HTTP::uri]]"  
        } 
     } 
     

    Aaron
  • hi this is not working... it rewrites only to the default.aspx without the parameter.
  • If you want to rewrite all URI's you can just remove the if clause:

     
     when HTTP_REQUEST {   
         Rewrite the URI to /default.aspx with a new parameter  
           and the value set to the URI encoded original URI   
        HTTP::uri "/default.aspx?original_uri=[URI::encode [HTTP::uri]]"  
     }  
     

    You'd need to change the application to URI decode the original_uri parameter value.

    Aaron