Forum Discussion
Forwarding request to server based on URL directory (and files inside it)?
Hello all,
I've searched and found nothing that i'm looking for. I've got a request from an internal team that they need to forward user requests who hit webpage behind a particular directory.
Incoming requests connecting to any page behind "www.site.com/SPECIFIC_DIRECTORY/." to a specific server + port. I thought I could handle this with the following iRule (shared) switch config:
---iRule--- when HTTP_REQUEST { switch [string tolower [HTTP::host]] {
www.site.com {pool POOL_NAME_1}
www.site.com/specific_directory { pool POOL_NAME_2}
}
}
...This configuration didn't work, so I was thinking of using a redirect iRule:
---iRule--- when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] {
"/specific_directory*" { HTTP::redirect "http://server:port" }
}
} ...likewise this isn't working because the server we're trying to forward to is only available internally. If you're not on the LAN you won't resolve the server IP.
Is there a proper way of handling this? Any suggestions or even documentation would be of great help.
Thank you, Michael
5 Replies
- Brad_Parker_139
Nacreous
Try this:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/specific_directory" } { pool } else { pool } }- mjacobs_189214
Nimbostratus
Ah, I see, thank you for the help Brad.. Question, can I roll this into my switch iRule that "looks" at host headers or do I need to create a new iRule and apply it to my Virtual Server? Below is a sample switch iRule which i'm hesitant to update since it's production, thank you again! when HTTP_REQUEST { switch [string tolower [HTTP::host]] { www.domain.com { pool } secure.domain.com { pool }
- Brad_Parker
Cirrus
Try this:
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/specific_directory" } { pool } else { pool } }- mjacobs_189214
Nimbostratus
Ah, I see, thank you for the help Brad.. Question, can I roll this into my switch iRule that "looks" at host headers or do I need to create a new iRule and apply it to my Virtual Server? Below is a sample switch iRule which i'm hesitant to update since it's production, thank you again! when HTTP_REQUEST { switch [string tolower [HTTP::host]] { www.domain.com { pool } secure.domain.com { pool }
- Brad_Parker
Cirrus
Well if you are going to have pool selection based on hostname and URI you will have to combine them or else they could conflict and not process they way you want. You could do someting like this which will prioritize the pool selection on the URI first then select to pool based on hostname if the URI doesn't match. Before throwing it in production I would try it in a non-prod first if at all possible.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] starts_with "/specific_directory" } { pool } else { switch [string tolower [HTTP::host]] { www.domain.com { pool } secure.domain.com { pool } } } }
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
