KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: URL Redirect Using HTTP Header
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: November 15, 2021

The 4D web sever can send a URL redirect by setting the "Location" in the HTTP response header. The example below shows a URL redirect being applied in the On Web Connection method. When the web server recieved a request a product, it sends a redirect to "productsResponse.xml" with a response. This is another way of redirecting URLs similar to command WEB SEND HTTP REDIRECT.

//On Web Connection Method
Case of
  :($1="/products?name=@")
  C_TEXT($redirectURL)
  $redirectURL:="productsResponse.xml"

  ARRAY TEXT($headerNames;0)
  ARRAY TEXT($headerValues;0)
  
  APPEND TO ARRAY($headerNames;"Location")
  APPEND TO ARRAY($headerValues;$redirectURL)
  
  WEB SET HTTP HEADER($headerNames;$headerValues)
End case