Forum Discussion
shafiul
Nimbostratus
Aug 08, 2016Set redirect to non trailing slash
We need to setup 301 redirect from all urls, starting from https://test.com/SOMECONTENT/ to appropriate URL on https - https://test.com/SOMECONTENT but without trailing slash. The same is for http - http://test.com/SOMECONTENT/ to https - https://test.com/SOMECONTENT
2 Replies
Hi Shafiul,
you may try the iRule below...
when HTTP_REQUEST { if { ( [string tolower [HTTP::path]] starts_with "/somecontent/" ) and ( [HTTP::path] ends_with "/" ) } then { if { [HTTP::query] eq "" } then { HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][string range [HTTP::path] 0 end-1]" } else { HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][string range [HTTP::path] 0 end-1]?[HTTP::query]" } } else { Request to other base directory or a path without trailing / detected } }Note: The iRule can be used for HTTP and HTTPS access as well.
Cheers, Kai
Hi Shafiul,
I've included
in my example, because you've asked for this... 😉/somecontent/Your modified version should include at least an additional exemption for the
(www-root) of your site. Otherwise a redirect loop may occour.../when HTTP_REQUEST { if { ( [HTTP::path] ends_with "/" ) and not ( [HTTP::path] equals "/" ) } then { if { [HTTP::query] eq "" } then { HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][string range [HTTP::path] 0 end-1]" } else { HTTP::respond 301 "Location" "https://[getfield [HTTP::host] ":" 1][string range [HTTP::path] 0 end-1]?[HTTP::query]" } } else { Request to other base directory or a path without trailing / detected } }Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
