28-Oct-2022 00:37
I have requirement that If URL is referring to a page that does not end with a "/" then redirect to the same URL ending with a "/" but it should not include below points:
1. ignore all request with Method POST
2. ignore all URLs starting with:
/WebResource.axd
/EPiServer.Forms/
3. URLs containing :
a query in the URL (indication is “?”)
URLs containing: /api/
28-Oct-2022 05:02
Perhaps something like this:
when HTTP_REQUEST {
if { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \
not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]/"
}
}
31-Oct-2022 10:50
Hi Kevin,
Thnk you very much for your reply. We have also created below irule ( with one more requirment --- If any letter in the URL contains upper case then redirect to a strict lower case version of the same URL):
when HTTP_REQUEST {
if { [HTTP::uri] ne [string tolower [HTTP::uri]] } { HTTP::respond 301 noserver Location [string tolower [HTTP::uri]] }
if { not ( [HTTP::uri] ends_with "/" ) and ! ([class match [string tolower [HTTP::path]] ends_with /DMZ/extensions]) and (! ([HTTP::uri] contains "/api/") or ! ([HTTP::uri] contains "/WebResource.axd") or !([HTTP::uri] contains "/EPiServer.Forms/") or !([HTTP::uri] contains "?") )} { HTTP::respond 307 Location "[HTTP::uri]/" }
}
In this irule we want to ignore all post method request which should not redirect, so let us know how we can achive this condition.
31-Oct-2022 11:00
when HTTP_REQUEST {
if { [HTTP::uri] ne [string tolower [HTTP::uri]] } {
HTTP::redirect "https://[HTTP::host][string tolower [HTTP::uri]]"
} elseif { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \
not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]/"
}
}
02-Nov-2022 11:02
Hi Kevin,
Thanks for your response. We have tested this and fulfilling our requirement but only one problem.
We want to ignore all post method request which should not redirect for first condition i.e. upper to lower case redirection. That means all post methods should not convert to lower case and should not get trail slash. So let us know how we can achieve this condition in existing irule.
02-Nov-2022 11:06
when HTTP_REQUEST {
if { ( [HTTP::method] ne "POST" ) and ( [HTTP::uri] ne [string tolower [HTTP::uri]] ) } {
HTTP::redirect "https://[HTTP::host][string tolower [HTTP::uri]]"
} elseif { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] starts_with "/Webresources.axd" ) && \
not ( [HTTP::uri] starts_with "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]/"
}
}
15-Nov-2022 09:41
Hi Kevin,
This logic works for us and now we have tested below irule as per the requirement:
when HTTP_REQUEST {
if { ( [HTTP::method] ne "POST" ) and ( [HTTP::uri] contains "*/Webresources.axd" ) }
{
HTTP::redirect "https://[HTTP::host][HTTP::uri]]"
} elseif { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] contains "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) && \
not ([class match [string tolower [HTTP::path]] ends_with /DMZ/extensions])
} {
HTTP::respond 301 Location "https://[HTTP::host][string tolower [HTTP::uri]]/"
}
}
Now we have additional condition which needs to be complete: If trailing slash and upper case is present then it needs to be redirect to lower case with trailing slash
Example: www.abc.com/vgh-BT-grt/ needs to be redirect to www.abc.com/vgh-bt-grt/
Please help us to fulfil this requirement by modifying above mentioned irule.
15-Nov-2022 12:07
when HTTP_REQUEST {
if { ( [HTTP::method] ne "POST" ) and ( [HTTP::uri] contains "*/Webresources.axd" ) } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]]"
} elseif { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] contains "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) && \
not ( [class match [string tolower [HTTP::path]] ends_with /DMZ/extensions] )
} {
HTTP::respond 301 Location "https://[HTTP::host][string tolower [HTTP::uri]]/"
} elseif { ( [HTTP::uri] ends_with "/" ) && ( [HTTP::uri] ne [string tolower [HTTP::uri]] ) } {
HTTP::respond 301 Location "https://[HTTP::host][string tolower [HTTP::uri]]"
}
}
06-Dec-2022 09:57
Hi Kevin,
Thanks for your update but unfortunately it did not worked and getting multiple redirections with infinite loops to meet below condition:
"If trailing slash and upper case is present then it needs to be redirect to lower case with trailing slash"
Could you please suggest any other way by modifying previusly shared irule to meet our requirement.
Again, thank you very much for your unconditional support and prompt response.
07-Dec-2022 14:43
Perhaps best thing to do now would be to inject some logging and see what's going on.
when HTTP_REQUEST {
log local0. "============================="
log local0. "Incoming request: [HTTP::uri]"
if { ( [HTTP::method] ne "POST" ) and ( [HTTP::uri] contains "*/Webresources.axd" ) } {
log local0. "-- request is POST and contains */Webresources.axd"
HTTP::redirect "https://[HTTP::host][HTTP::uri]]"
} elseif { not ( [HTTP::uri] ends_with "/" ) && \
not ( [HTTP::method] eq "POST" ) && \
not ( [HTTP::uri] contains "/EPiServer.Forms/" ) && \
not ( [HTTP::uri] contains "?" ) && \
not ( [HTTP::uri] contains "/api/" ) && \
not ( [class match [string tolower [HTTP::path]] ends_with /DMZ/extensions] )
} {
log local0. "-- request is not POST, doesn't end with / and doesn't contain (?, /api/, /EPiServer.Forms/)"
HTTP::respond 301 Location "https://[HTTP::host][string tolower [HTTP::uri]]/"
} elseif { ( [HTTP::uri] ends_with "/" ) && ( [HTTP::uri] ne [string tolower [HTTP::uri]] ) } {
log local0. "-- request ends with / and not lowercase"
HTTP::respond 301 Location "https://[HTTP::host][string tolower [HTTP::uri]]"
}
}
View the logs:
tail -f /var/log/ltm
Please post what you find.