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 - ...
Kai_Wilke
MVP
Sep 02, 2016Hi Shafiul,
I've included
/somecontent/ in my example, because you've asked for this... 😉
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
