Forum Discussion

0_173149's avatar
0_173149
Icon for Nimbostratus rankNimbostratus
Apr 29, 2016

Using wildcards in uri redirection in iRules

I currently have

 

when HTTP_REQUEST { if { [HTTP::path] equals "/" } { HTTP::redirect "/toplevel/src/main/webapp/project.html" } }

 

I need to make it so I can use the subdirectory as a starting point - basically skipping over /toplevel/ as that will change as more projects get added

 

ex -- instead of starting at mydomain.com/ I need to start at mydomain.com//

 

and then append the /src/main/webapp/project.html

 

Thanks

 

2 Replies

  • OK -- since I got no feedback - and figured this out - I'll add what I did in case someone else finds themselves in the same problem --

    Basically if they don't send the complete url - I'm separating the PATH and the URI an updating it that way.

    If anyone has a better suggestion - type in 🙂

    thanks

    when HTTP_REQUEST {

    if { not ( [HTTP::uri] contains "." ) } {
        HTTP::uri [HTTP::uri]/src/main/webapp/Project.html
                HTTP::redirect [HTTP::uri]
    } 
    

    }

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Can you clarify the requirements a bit? What you're looking for is certainly doable, but I'm unclear on the precise syntax. Are you saying that all content on the OWS (Origin Web Server) is will be under a root called "toplevel" but that you don't want the user to see that in the URL? If so, what part of the path would indicate which project they're accessing?

    Also, it looks like you're assigning a new value to HTTP::uri before using it in the redirect. However, although HTTP::uri can be read, it has a double function in that changing the value is intended to alter the value that's being sent to the OWS. You'll want to either use a variable or use the statement itself in the redirect. The latter would be preferred as it is more efficient.

    Lastly, using HTTP::redirect is inefficient as it uses a 302 (temporary redirect) rather than a 301 (permanent redirect). If the redirect for a given URL will always be the same you'll want to use a 301. To accomplish this you need to use

    HTTP::respond
    rather than
    HTTP::redirect
    .

    Having said all that, should it really be a redirect or would it be better to make it transparent to the user? (i.e. route the request to the appropriate resource on the OWS but keep the URL in the browser the same)