Forum Discussion
Assistance with iRule for substitue/redirect - LTM
Web developer would like this behavior:
so if a GET request is made to 'testsite2.com/unsubscribe.php[?params¶ms]' it should be forwarded to https://testsite2.com/testapp/unsubs/unsubscribe.php[?params¶ms]
Tried this with a variation of a previous DevCentral response:
when HTTP_REQUEST { if { ([HTTP::host] eq "testsite2.com") and ([string tolower [HTTP::uri]] ends_with "/unsubscribe.php") } { HTTP::respond 308 Location "; } }
Seems to be resulting in a 404 when parameters are supplied stating: /unsuscribe.php (The requested resource is not available)
Thanks in advance,
Doug
Hi,
what will happen if you directly went to this?
http://testsite2.com/testapp/unsubs/unsubscribe.php
try this:
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { HTTP::respond 301 noserver Location "/testapp/unsubs/unsubscribe.php" } }
OR
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { HTTP::redirect "http://testsite2.com/testapp/unsubs/unsubscribe.php" } }
SELECTED ANSWER - This will keep your parameters and will only replace the url:
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { set uri [string map {"/unsubscribe.php" "/testapp/unsubs/unsubscribe.php"} [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$uri" } }
- Dvirus_297774Altocumulus
Hi,
what will happen if you directly went to this?
http://testsite2.com/testapp/unsubs/unsubscribe.php
try this:
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { HTTP::respond 301 noserver Location "/testapp/unsubs/unsubscribe.php" } }
OR
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { HTTP::redirect "http://testsite2.com/testapp/unsubs/unsubscribe.php" } }
SELECTED ANSWER - This will keep your parameters and will only replace the url:
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { set uri [string map {"/unsubscribe.php" "/testapp/unsubs/unsubscribe.php"} [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$uri" } }
- dwhite12_255934Nimbostratus
I used the second method and the redirection is now successfully working but i get a response like this:
https://testsite2.com/testapp/unsubs/unsubscribe.php
{"status":"BAD_REQUEST","message":"Invalid URL"}
This initial GET is composed like this:
https://testsite2.com/unsubscribe.php?mid=10176&cid=4758131&oid=2&sid=22810&vid=ASmith&r=MC2
It's as if it's not passing the parameters along? I'm just guessing.
Thanks.
- Dvirus_297774Altocumulus
let's try this:
when HTTP_REQUEST { if { [HTTP::host] equals "testsite2.com" && [HTTP::uri] starts_with "/unsubscribe.php" } { set uri [string map {"/unsubscribe.php" "/testapp/unsubs/unsubscribe.php"} [HTTP::uri]] HTTP::redirect "http://[HTTP::host]$uri" } }
- dwhite12_255934Nimbostratus
Got a response back from the developer and he said it's good to go.
Thanks!
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