Hi Forum, I am having one issue of syntax, i have already an irule available for 2 requirements (1 and 2 below) which is working fine. Issue is i need to incorporate solution for the 3rd requirement below.
1- If anyone types HTTP based mynetwork.us then it should be redirected to HTTPS based https://www.mynetwork.us 2- If in path there is /autodiscover/autodiscover.xml then it should be redirected to autodiscover site with 301 permanent redirected message. 3- If there is / at the end of any URI then / at then end of URI should be removed and client should get back one with removed /.
Point 1 and 2 is working fine. Now only requirement is to add functionality of point 3 that if there is / at the end in any URI the it should be trimmed off.I have tried this code to integrate in existing one but having some syntax errors.
It will remove the / at end and redirect back to the user modified uri with removed /. Need your expert opinion how this will be incorporated in below detailed irule to achieve the objective.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] ends_with “/” } {
Hey claudio many thanks for your quick response and inputs. Regarding your question, requirement is if user types only mynetwork.us then it should redirect to https://www.mynetwork.us.
However with your above verified code, can you confirm if all 3 mentioned below requirements are met ? I have not tested it yet so once i test it will update you accordingly. Thanks once again for your valuable input.
Hi Claudio you are right, i have got chance to test it and it worked like a charm but it has only one issue if typed mynetwork.us then site does not work because browser puts / at the end which is removed by f5. If i type like mynetwork.us/en etc then it works. So how can we define if / is immediate after host or in between complete uri it should not be removed and only removed at end of uri ?
OK, if I understood well, needs to check if the uri is not simply “/” so don’t need to be redirected.
Please let me know if I got it.
[ ]
when HTTP_REQUEST {
HTTP::header remove Accept-Encoding
STREAM::disable
redirect autodiscover requests to autodiscover site https
if { [string tolower [HTTP::path]] equals "/autodiscover/autodiscover.xml" } {
HTTP::respond 301 Location https://autodiscover.mynetwork.us/autodiscover/autodiscover.xml
redirect mynetwork.us to https://www.mynetwork.us along with any uri
} elseif { [string tolower [HTTP::host]] equals "mynetwork.us" } {
HTTP::respond 302 Location https://www.mynetwork.us[string trimright [HTTP::uri] "/"]
redirect if uri is not / but ends with it
} elseif { !([HTTP::uri] equals "/") and [HTTP::uri] ends_with "/" } {
HTTP::respond 302 Location http://[HTTP::host][string trimright [HTTP::uri] "/"]
}
}
Thanks Claudio for your excellent response. I have not tested it yet since waiting for change approval as soon as it is done will be able to test it. Meanwhile i have just one question that how can i incorporate my existing below switch rule in above mentioned rule or if not feasible then how to achieve below requirement in if else above statement.
switch -glob [string tolower [HTTP::uri]] {
"/gr/mypage.xml*" {
set find "/gr/mypage.xml"
set replace "/gr-mypage.xml"
HTTP::uri [ string map -nocase "$find $replace" [HTTP::uri]]
set rewrite 1 }
"/fr/mypage.xml*" {
set find "/fr/mypage.xml"
set replace "/fr-sitemap.xml"
HTTP::uri [ string map -nocase "$find $replace" [HTTP::uri]]
Hi Claudio thanks for your reply, i have tried this rewrite but for some reason it seems rewrite is not working. I have tested through wireshark on server and getting gr/mypage.xml in Get instead of gr-mypage.xml. For return command after http::respond seriously not sure.
If the request does not fall under the redirect conditions, it should rewrite the URI and deliver it to the servers. Please, add log line eg: log local0. “URI: [HTTP::uri]” below that line HTTP::uri [string map -nocase “$ find $ replace” [HTTP :: uri]] and see the LTM log eg: “tail -f /var/log/ltm” [ ]