Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Mar 27, 2014

Catching parameters in URI, rewriting.

We are migrating to a new forum system, and need to be able to support users who may have certain threads bookmarked. The topics and threads have all been imported into the new forum.

I have a simple rule already working in order to catch the main topics:

http://oldforumsite.com/forum_topics.asp?FID=37&title=asdf

and rewrite to:

http://newforumsite.com/default.aspx?g=topics&f=37

I need to be able to support individual forum threads as well. We need to catch forum_topics.asp, and forum_posts.asp, and rewrite them to topics and posts.

Old Forum Topics:

http://oldforumsite.com/forum_topics.asp?FID=37&title=asd

Old Forum Posts

http://oldforumsite.com/forum_posts.asp?TID=57521&FID=37&title=asdf-asd-asd-asd

New Forum Topics

http://newforumsite.com/default.aspx?g=topics&f=37

New Forum Posts

http://newforumsite.com/default.aspx?g=posts&t=57521

I have the following iRule in place, which checks the URI to see if it contains FID, or TID, and redirects properly to the corresponding topic in the new forum system. What I am having difficulty figuring out is how to catch a URI if it has either FID, TID, or both FID and TID, and then rewrite. You'll notice above, for individual forum posts, there is both a TID and an FID.

If the URI contains FID with parameters, then it needs to rewrite to the New Forum Topic. If the URI contains a TID AND an FID with parameters, then it needs to rewrite to to the New Forum Post.

Here's what I have so far - this works for rewriting to the correct forum topics, which displays a listing of individual forum posts. Can anyone help me with next steps?

when HTTP_REQUEST {
    if { [HTTP::uri] contains "FID" } {
        HTTP::redirect "http://newforumsite.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
    }
    if { [HTTP::uri] contains "TID" } {
        HTTP::redirect "http://newforumsite.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
    }
}

8 Replies

  • I'm going to take a guess and say that I'd have to check to see if the URI contains forum_topics AND FID, or forum_posts AND TID, and rewrite.
  • I don't think you are far off. Your second example contains both the FID and TID parameters, but in this case you ignore the FID one. If that is how it is meant to work, simply redirect by TID if it exists. If not, redirect by FID if it exists. i.e, it looks to me like TID takes priority over FID. Would the following do?

    when HTTP_REQUEST {
        if { [HTTP::query] contains "TID=" } {
            HTTP::redirect "http://newforumsite.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
            return
        }
    
        if { [HTTP::query] contains "FID=" } {
            HTTP::redirect "http://newforumsite.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
            return
        }
    
        HTTP::redirect "http://newforumsite.com/"
    }
    
    • uni_87886's avatar
      uni_87886
      Icon for Cirrostratus rankCirrostratus
      If not, give before and after examples of all the combinations you want covered
  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    I don't think you are far off. Your second example contains both the FID and TID parameters, but in this case you ignore the FID one. If that is how it is meant to work, simply redirect by TID if it exists. If not, redirect by FID if it exists. i.e, it looks to me like TID takes priority over FID. Would the following do?

    when HTTP_REQUEST {
        if { [HTTP::query] contains "TID=" } {
            HTTP::redirect "http://newforumsite.com/default.aspx?g=posts&t=[URI::query [HTTP::uri] TID]"
            return
        }
    
        if { [HTTP::query] contains "FID=" } {
            HTTP::redirect "http://newforumsite.com/default.aspx?g=topics&f=[URI::query [HTTP::uri] FID]"
            return
        }
    
        HTTP::redirect "http://newforumsite.com/"
    }
    
    • uni's avatar
      uni
      Icon for Altostratus rankAltostratus
      If not, give before and after examples of all the combinations you want covered
  • I think we have a winner!!! My only question left is - the very last redirect outside of the if statement - is that supposed to be designated the default redirect?

     

    I'll give it a shot and do some more testing. I appreciate the help

     

    • uni's avatar
      uni
      Icon for Altostratus rankAltostratus
      Yes, the last redirect is if there is neither a TID nor a FID parameters.
    • Joe_Pipitone's avatar
      Joe_Pipitone
      Icon for Nimbostratus rankNimbostratus
      I meant, do I need to specify "default" in the last part of the rule - for example: default { HTTP::redirect "http://newforumsite.com/" }