Forum Discussion
Redirect host and path but keep query string on redirect
I need to redirect a request to a new host and path but keep the query string the same. Can someone help me with the best way of doing this?
If request contains “https://olddomain.com/SelfServ/WebContactResponse.aspx?”
then Redirect to
https://new-domain.com/my-account/w....aspx?$uri"
}
}
Thanks in advance for the help!
Dave
5 Replies
- Michael_Yates
Nimbostratus
Hi Davean,
You can use the [HTTP::query] command to have it added onto the end.
NOTE: The HTTP::query value does not include the "?".
Try this:when HTTP_REQUEST { if { [string tolower [HTTP::path]] equals "/selfserv/webcontactresponse.aspx" } { HTTP::redirect "https://new-domain.com/my-account/web-contact-response.aspx?[HTTP::query]" } } - Davean_Hosang_1
Nimbostratus
Thank you Michael! If the path will be changed in the redirect why do I need the "string tolower" ? - Michael_Yates
Nimbostratus
The "string tolower" takes the value of the [HTTP::path] and puts everthing in lower case.
So if someone entered "/SelfServ/WebContactResponse.aspx" or "/SELFSERV/WEBCONTRACTRESPONSE.ASPX" the value would be put into all lower case "/selfserv/webcontactresponse.aspx" (a known state) for an accurate comparison to trigger the event.
It does not change the actual value that will be sent to the server. Since the URI Value of a URL is case sensitive and doing so may cause your application to fail. - shawno_84086
Nimbostratus
There's a problem with this, it will redirect to: https://new-domain.com/my-account/web-contact-response.aspx? if there is no query.
Here's what I do:
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] equals "/selfserv/webcontactresponse.aspx" } {
if { [HTTP::query] ne "" }{
HTTP::redirect "https://new-domain.com/my-account/web-contact-response.aspx?[HTTP::query]"
else {
HTTP::redirect "https://new-domain.com/my-account/web-contact-response.aspx"
}
}
I came to this thread wondering if the performance was the same to do:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] equals "/selfserv/webcontactresponse.aspx" } {
HTTP::redirect "https://new-domain.com/my-account/web-contact-response.aspx"
elseif { [string tolower [HTTP::path]] equals "/selfserv/webcontactresponse.aspx" } {
HTTP::redirect "https://new-domain.com/my-account/web-contact-response.aspx?[HTTP::query]"
}
}
- Arie
Altostratus
Technically it should not matter if there's a superfluous "?" at the end of the URL.
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
