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
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]"
}
}
Thank you Michael! If the path will be changed in the redirect why do I need the “string tolower” ?
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.
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
March 11, 2013, 7:05pm
6
Technically it should not matter if there’s a superfluous “?” at the end of the URL.