Forum Discussion

aguley_212957's avatar
aguley_212957
Icon for Nimbostratus rankNimbostratus
Nov 17, 2015

iRule Redirect

I am very new to iRules. I have the first portion of my rule working correctly

 

when HTTP_REQUEST {

 

if {[HTTP::path] eq "/"}{ HTTP::redirect "/ABC/" } }

 

I also want to add to this rule so that if someone types anything else after the / it redirects them back to the /ABC site.

 

So right now if you go to https://mysite.com/ it redirects to https://mysite.com/abc just like I want it to.

 

If the user goes to https://mysite.com/zzz I want it to redirect them to https://mysite.com/abc

 

Any guidance would be appreciated.

 

Thanks

 

  • Give this a try. Essentially if the path doesn't start with /abc redirect it permanently to https://mysite.com/abc/.

    when HTTP_REQUEST {
        if { not ([string tolower [HTTP::path]] starts_with "/abc") }{
            HTTP::respond 301 noserver Location "https://mysite.com/abc/"
        }
    }
    
  • Give this a try. Essentially if the path doesn't start with /abc redirect it permanently to https://mysite.com/abc/.

    when HTTP_REQUEST {
        if { not ([string tolower [HTTP::path]] starts_with "/abc") }{
            HTTP::respond 301 noserver Location "https://mysite.com/abc/"
        }
    }
    
    • aguley_212957's avatar
      aguley_212957
      Icon for Nimbostratus rankNimbostratus
      Thanks for the response. When I put that in as the irule i get the following from my browser: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
    • Brad_Parker_139's avatar
      Brad_Parker_139
      Icon for Nacreous rankNacreous
      If this is just happening in Firefox, I think it may be unique to the browser. Try flushing cache and cookies.
  • Give this a try. Essentially if the path doesn't start with /abc redirect it permanently to https://mysite.com/abc/.

    when HTTP_REQUEST {
        if { not ([string tolower [HTTP::path]] starts_with "/abc") }{
            HTTP::respond 301 noserver Location "https://mysite.com/abc/"
        }
    }
    
    • aguley_212957's avatar
      aguley_212957
      Icon for Nimbostratus rankNimbostratus
      Thanks for the response. When I put that in as the irule i get the following from my browser: The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies.
    • Brad_Parker's avatar
      Brad_Parker
      Icon for Cirrus rankCirrus
      If this is just happening in Firefox, I think it may be unique to the browser. Try flushing cache and cookies.
  • Hi, Hope below iRule will be helpful.

                when HTTP_REQUEST {
                   if { [HTTP::uri] eq "/" } {
                   HTTP::redirect "https://mysite.com/abc"
                             }
                        }
    
  • Hi,

     

    I've encountered this kind of problem in the past and resolved my issue with :

     

    Local Traffic => Profiles => Services => Rewrite => Rewrite Mode : URI Translation.

     

    Hope it help