Forum Discussion
301 redirect with uri rewrite
Hello, I have a need to create both a 301 redirect and also a URI rewrite in the same iRule.
Currently I have a site that I'll need to perform a 301 redirect on that is similar to https://some.example.com/content/the_uri_info_to_keep that needs to be directed to https://another.example.com/the_uri_info_to_keep.
Thank you for assisting, love this community.
- William_Turner_
Nimbostratus
Thoughts on if this iRule would meet the above needs and perform the correct 301 redirect?
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "some.example.com" { if { [HTTP::uri] starts_with "/content"}{ set uri [HTTP::uri [string map {"/content" ""} [HTTP::uri]]] HTTP::respond 301 Location "https://another.example.com$uri" } default {HTTP::respond 301 Location "https://another.example.com[HTTP::uri]"} }
}
Your iRule looks perfect.
- NicCage
Nimbostratus
The content of the iRules is perfect. I just formatted the iRule a bit and added a missing closing bracked.
See the formated output below:
when HTTP_REQUEST { switch [string tolower [HTTP::host]] { "some.example.com" { if { [HTTP::uri] starts_with "/content"}{ set uri [HTTP::uri [string map {"/content" ""} [HTTP::uri]]] HTTP::respond 301 Location "https://another.example.com$uri" } } default {HTTP::respond 301 Location "https://another.example.com[HTTP::uri]"} } }
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