Forum Discussion
slomah_85788
Nimbostratus
Jun 10, 2009Appending iRule
Hi,
I have requested to create iRule which will add appending to url, as the customer will write (http://mycompany.com ) and the application won’t work unless you write the following (http://mycompany.com/test/app.aspx )
1) I created the following irule but the pictures on the page doesn’t appear
when HTTP_REQUEST {
if { not ([HTTP::uri] starts_with "/test") } {
HTTP::uri /test/app.aspx [HTTP::uri]
}
}
2) I used redirection irule like this and it works but I don’t know if this will affect the application
when HTTP_REQUEST {
if {
[HTTP::uri] equals "" or [HTTP::uri] equals "/" } {
HTTP::redirect http://mycompany.com/test/app.aspx }}
I would like if someone help me in No.1 to make work.
5 Replies
- For the first iRule, let's say your incoming URI is "/foobar". You are resetting the URI to the "/test/app.aspx /foobar". I'm assuming that isn't what you want to do. If you just want to change the URI to /test/app.aspx" then leave out your trailing [HTTP::uri] from the assignment.
-Joe - slomah_85788
Nimbostratus
You mean to remove [HTTP::uri] and make like this:
when HTTP_REQUEST {
if { not ([HTTP::uri] starts_with "/test") } {
HTTP::uri /test/app.aspx
}
}
But this gives the same results as the pictures didn’t appear. - hoolio
Cirrostratus
If you just want to rewrite requests to the root document (path equals /), you could use this:when HTTP_REQUEST { Check if path is / if {[HTTP::path] eq "/"}{ Rewrite path to /test/app.aspx HTTP::path "/test/app.aspx" } }
If you want to prepend a string to all URIs if it's not there already, you can use a rule like this:when HTTP_REQUEST { Check if path doesn't already start with /test/ if { not ([HTTP::path] starts_with "/test/")}{ Rewrite path by prepending "/test/" HTTP::path "/test/[HTTP::path]" } }
Note that if you don't care about inspecting the query string it should be more efficient to modify just the path using HTTP::path.
Aaron - Matt_108113
Nimbostratus
All,
I have an append/redirect question.
Right now I am doing a straight redirect based on two different paths, but now my users want to add arguments to the paths how can I do this? Below is the current rule and an example of the url the users are trying to use.
when HTTP_REQUEST {
if { [HTTP::uri] equals "/dev" } {
log local0. "Found the uri /"
HTTP::redirect "https://www.server1.com:4444/dev"
}
if { [HTTP::uri] equals "/test" } {
log local0. "Found the uri /"
HTTP::redirect "https://www.server1.com:4444/test"
}
}
so basically the redirection takes you to the apache server running on 4444 instead of 443, but the question is if a user hit https://www.server1.com/test/USERNAME -or- https://www.server1.com/dev/PROJECT the redirect takes them to the mainpage (since that is what the rule tells it to do), but how can I grab the PROJECT code or the USERNAME and pass that to the redirect or append it to the redirect?
Thanks,
Matt - hoolio
Cirrostratus
Hi Matt,
It would help if you created a new post for your question. You can parse the fields in the path using getfield:
[getfield "/path1/path2/path3" "/" 3] returns path2
So [getfield [HTTP::path] "/" 3] for a request to /test/USERNAME would return USERNAME.
If you create a new post, can you add a few examples of what you'd like the original and modified requests to look like?
Thanks,
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects