Forum Discussion
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
- Joe_Pipitone
Nimbostratus
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. - uni_87886
Cirrostratus
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
Cirrostratus
If not, give before and after examples of all the combinations you want covered
- uni
Altocumulus
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
Altocumulus
If not, give before and after examples of all the combinations you want covered
- Joe_Pipitone
Nimbostratus
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
Altocumulus
Yes, the last redirect is if there is neither a TID nor a FID parameters. - Joe_Pipitone
Nimbostratus
I meant, do I need to specify "default" in the last part of the rule - for example: default { HTTP::redirect "http://newforumsite.com/" }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com