Forum Discussion

Alexis_Verb__23's avatar
Alexis_Verb__23
Icon for Nimbostratus rankNimbostratus
Jul 01, 2011

Irule redirect --> problem with character "#"

Hello,

 

 

I'm facing trouble with creating a simple redirect irule. I want to redirect everthing from http://mywebsite.com/{sth} to http://www.mywebsite.com/{sth}.

 

 

Here is the irule I've written :

 

 

when HTTP_REQUEST {

 

 

if { [HTTP::path] equals "/" and

 

([HTTP::header "User-Agent"] contains "iPhone"

 

or [HTTP::header "User-Agent"] contains "iPod"

 

or [HTTP::header "User-Agent"] contains "Android"

 

or [HTTP::header "User-Agent"] contains "Apple Mobile Safari")} {

 

HTTP::respond 301 "Location" "http://mobile.mywebsite.fr/news/"

 

}

 

elseif { [HTTP::host] equals "mywebsite.fr" }{

 

HTTP::respond 301 "Location" "http://www.mywebsite.fr[HTTP::uri]"

 

}

 

else {

 

pool mywebsite-pool

 

}

 

}

 

 

 

Anayway, in the [HTTP::uri], I often have the "" character, and it does not work.

 

 

Example :

 

 

If I try with http://mywebsite.fr//test I am redirected to http://www.mywebsite.fr/.

 

 

Does anyone know how to deal with that?

 

 

Thanks a lot,

 

Alexis.

 

3 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    It looks like you're making this a lot more complicated than it needs to be, unless I'm missing something. If all you want to do is ensure there is always a www on the host, all you'd need is:

    
    when HTTP_REQUEST {
      if{[HTTP::host] eq "mywebsite.com"] {
        HTTP::redirect "http://www.mywebsite.com[HTTP::uri]"
      }
    }
    

    That should take care of it for you regardless of the URI.

    If there is something more complicated that you're trying to do, I missed it. Let me know what it is and I'll take a look.

    Colin
  • Clients shouldn't include an anchor tag in the request they send to the server. It's something that is used clientside on the browser to load specific content on the page. If you log the HTTP::uri value, you should see that the tag isn't present in requests.

     

     

    Aaron
  • @Colin,

     

    Thanks for the tip, I'll use the HTTP:redirect which seems much simpler.

     

     

    @hoolio

     

    Thanks for the explanation. I understand now why I didn't see the anchor tag when logging it.

     

     

    Alexis.