Forum Discussion
redirect to new path
Hi, i have this url https://abc.com/site1/online/index.html and want to redirect to this site https://abc.com/online/index.html but it doesn't work.
I try to this irule:
when HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::path] { "site1/online/"{ URI::path /online/ pool 1.1.1.1 } "site1/"{ URI::path /online/" pool 1.1.1.1 } }
}
or this irule when HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::path] { "site1/online/"{ HTTP::redirect "/online" pool 1.1.1.1 } "site1/"{ HTTP::redirect "/online" pool 1.1.1.1 } }
} Thanks in advance for the help!
13 Replies
- Michael_Jenkins
Cirrostratus
If you want to use a wildcard in your switch you'll need to add the
to your criteria and/or the initial*
./Something like
or/site1/online/*
.*/site1/online/* - IheartF5_45022
Nacreous
If you want to issue a clientside redirect try this (I use HTTP::respond as I like to use 301, and also like to use 'noserver' to hid the Server:BigIP header).
HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::path] { "site1/online/index.html"{ 301 Redirect HTTP::respond 301 noserver Location "/online" return } "online/"{ pool 1.1.1.1 } } }- johtte_168100
Nimbostratus
Hi, thanks for this another idea. but if we check later the same url but redirect to another pool for example First request -> site1/online/index.html, after that change the path to /online/ redirect to pool 1.1.1.1 Second request -> site1/online/authenticate.html ->change the path to /online redirect to pool 2.2.2.2 when HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::path] { "/site1/online" { HTTP::respond 302 noserver Location "/online" return } "/online" { pool 1.1.1.1 } } switch -glob [HTTP::uri] { "/site1/online/authenticate.html" { HTTP::respond 302 noserver Location "/online" return } "/online"{ pool 2.2.2.2 } } } Something like this? Thanks for your help
- IheartF5_45022
Nacreous
I think maybe you actually want to transparently rewrite and select pool based on incoming request rather than actually redirect (which sends a response to the client instructing it to re-request a new URL). Does this look like what you want (this assumes pl_pool has member 1.1.1.1:80 and pl_pool2 has member 2.2.2.2:80)?;-
HTTP_REQUEST { Check the requested path switch -glob [HTTP::path] { "/site1/online/index.html"{ HTTP::path "/online" pool pl_pool1 } "/site1/online/authenticate.html"{ HTTP::path "/online" pool pl_pool2 } } }Alternatively if you really do want to redirect this would be an option;
when HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::uri] { "/site1/online*" { HTTP::respond 302 noserver Location "/online?default" return } "/site1/online/authenticate.html" { HTTP::respond 302 noserver Location "/online?authenticate" return } "/online?default"{ HTTP::uri [HTTP::path] pl_pool1 } "/online?authenticate"{ HTTP::uri [HTTP::path] pl_pool2 } } } - johtte_168100
Nimbostratus
ïf i used https from the client and https to the server too. Some changes in the irule should i have?
Thanks for you help
- IheartF5_45022
Nacreous
No shouldn't need any change as long as you have your clientssl and serverssl profiles assigned to the virtual. - johtte_168100
Nimbostratus
"/online?default"{ HTTP::uri [HTTP::path] -> this part i need to change something? pl_pool1 } - IheartF5_45022
Nacreous
Nope
- afedden_1985
Cirrus
looking at what you wanted to do, Redirect> https://abc.com/site1/online/index.html to this site > https://abc.com/online/index.html I would do that using this irule with an external data group and apply the irule to your VIP hosting abc.com
Create external data group name REDIR 1st create a text file on your workstation called REDIR and add this line to it "/site1/online/index.html" := "abc.com/online/index.html" save the file REDIR.txt From Local Traffic > iRules : Data Group List click Create Data Group name REDIR Type External File import your file set File Contents to String Key / Value Pair Separator := Data Group Name REDIR click on Import
Now build the irule which references the external data group iRule called REDIR
when HTTP_REQUEST {
set urlredir [class match -value [HTTP::uri] contains REDIR]
if { $urlredir ne "" }{
log local0. "REDIRECT - path : [HTTP::path] - referrer : [HTTP::header "Referer"]"
set redir [string map "[HTTP::path] $urlredir" [HTTP::uri] ]
HTTP::redirect "https://$redir"
}
}apply the iRule to the VIP. You can add as many Redirects to the external file that you want. the file is stored in System > File Management : Data Group File List
- johtte_168100
Nimbostratus
Thanks for your response, how can i redirect to specific pool for example: site1/online/index.html redirect to pool 1.1.1.1 using path /online/index.html and if site1/online/authenticate.html redirect to pool 2.2.2.2 using path online/authenticate.html.
Best regards
- afedden_1985
Cirrus
Your original request was how to redirect clients from 1 site to another. This new description doesn't need a redirect what your describing is layer 7 load balancing based on the URI path. That's a single VIP that will inspect the URI and make a load balancing decision to determine which pool to send to. Is that what you need help with?
- johtte_168100
Nimbostratus
Yes, i need to balance based on Uri PATH and also change the URI:path before redirect to correct pool.
- Michael_Jenkins
Cirrostratus
In that case, you could try something like this:
when HTTP_REQUEST { Check the requested path with wildcard matching switch -glob [HTTP::path] { "/site1/online/*" { Trim the "/site1" from the front of the path HTTP::path [string range [HTTP::path] 6 end] Update the pool pool 192.168.111.90 } } }
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