Forum Discussion

PacketHead_4009's avatar
PacketHead_4009
Icon for Nimbostratus rankNimbostratus
Nov 04, 2010

URI Redirect to main page

Hello,

 

 

I have a few iRules that do something similar to what I am looking for but not specifically what I am trying to do.

 

 

Basically I have a VIP for www.mysite.com. I have some old links that no longer work due to content change and upgrades but users have these links stored as favorties and in their system (i.e. www.mysite.com/user/manpage/home and www.mysite.com/admins/manpage/tools )

 

 

I want to create an iRule to redirect the users back to the main page if they have any of the URLs listed above. This seems simple enough with some if and else statements but I'm still new to iRule coding.

 

 

Any help would be appreciated!

 

 

- James

 

6 Replies

  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Hi James,

    Something like this would probably do the trick:

    when HTTP_REQUEST {
    switch -glob [HTTP::path] {
    "/user/manpage/home/*" -
    "/admins/manpage/tools/*" -
    default {
    HTTP::redirect http://www.mysite.com
    }
    }
    }

    Add and remove more paths and/or wildcards as necessary.

    -George
  • Hello George,

     

     

    That looks like it should work. Now my other question. How can I stack these so that I have the URL "/admins/manpage/tools*" redirect to www.mysite.com/tools/new instead of the main site ? Can I stack it on the same iRuel somehow?

     

     

    Thanks,

     

     

    James
  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    Hi James,

    The hyphens just say, "drop through to the next action." In this case it will drop all the way through to the default action, which is redirect to http://www.mysite.com. If you want to redirect on a specific URL, do this:

    when HTTP_REQUEST {
    switch -glob [HTTP::path] {
    "/admins/manpage/tools/*" { HTTP::redirect http://www.mysite.com/tools/new }
    "/user/manpage/home/*" -
    default {
    HTTP::redirect http://www.mysite.com
    }
    }
    }

    Does that help?

    -George
  • Ok, let me take a step back. Looks like it is looping. So my main VIP/site is www.mysite.com

     

     

    If I just do your basic URL as follows:

     

     

    when HTTP_REQUEST {

     

    switch -glob [HTTP::path] {

     

    "/user/manpage/home/homesite.htm" -

     

    default {

     

    HTTP::redirect http://www.mysite.com

     

    }

     

    }

     

    }

     

     

    I get a browser error stating the page it going in a redirect loop. Please note that I changed the "/user/manpage/home/*" wildcard to a specific file in that directory if that makes a difference.

     

     

    Any ideas? If I redirect it to a page other than the VIP/site, the redirect works fine.
  • George_Watkins_'s avatar
    George_Watkins_
    Historic F5 Account
    I don't know why you are getting stuck in a redirect loop. My first guess would be that you are also redirecting at the web server. The iRule itself should not be putting you in a redirect loop.

     

     

    -George
  • If /user/manpage/home/homesite.htm references any other objects like css, images, etc, then you'll get a loop. At a minimum, you'd want to allow (not redirect) that URI and any URIs it references.

     

     

    Aaron