F5 Sites
  • F5.com
  • F5 Labs
  • MyF5
  • NGINX
  • Partner Central
  • Education Services Portal (ESP)
Contact
  • Under Attack?
  • F5 Support
  • DevCentral Support
  • F5 Sales
  • NGINX Sales
  • F5 Professional Services
Skip to contentBrand Logo
Forums
CrowdSRC
Articles
GroupsEventsSuggestionsHow Do I...?
RegisterSign In
  1. DevCentral
  2. Articles
  3. Technical Articles

Rewriting Redirects

While best practices for virtualized web applications may indicate that relative self-referencing links and redirects (those which don't include the protocol or the hostname) are preferable to absolu...
Published May 13, 2008
Version 1.0
ace
application delivery
BIG-IP
deployment
migration
tech tip
tutorial
Deb_Allen_18's avatar
Deb_Allen_18
Historic F5 Account
Joined September 25, 2004
View Profile
jurgenvdmark_14's avatar
jurgenvdmark_14
Icon for Nimbostratus rankNimbostratus
May 08, 2014
I've been looking for a method to change absolute redirects into relative redirects. The following does the trick:

 

 

when HTTP_RESPONSE {

 

if { [HTTP::is_redirect] } {

 

Replace absolute redirect with relative redirect

 

HTTP::header replace Location [regsub {https?://[^/]*/} [HTTP::header value location] "/"]

 

}

 

}

 

 

Basically it looks for every HTTP location starting with "http://" or "https://" and then looks for any character other than "/"/ and replaces it with a single "/"

Help guide the future of your DevCentral Community!

What tools do you use to collaborate? (1min - anonymous)

ABOUT DEVCENTRAL

DevCentral NewsTechnical ForumTechnical ArticlesTechnical CrowdSRCCommunity GuidelinesDevCentral EULAGet a Developer Lab LicenseBecome a DevCentral MVP

RESOURCES

Product DocumentationWhite PapersGlossaryCustomer StoriesWebinarsFree Online CoursesTraining & Certification

SUPPORT

Manage SubscriptionsProfessional ServicesCreate a Service RequestSoftware DownloadsSupport Portal

PARTNERS

Find a Reseller PartnerTechnology AlliancesBecome an F5 PartnerLogin to Partner Central

©2026 F5, Inc. All rights reserved.
TrademarksPoliciesPrivacyCalifornia PrivacyDo Not Sell My Personal Information