KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Simple configuration to enable virtual hosting in 4D
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: November 5, 2013

Virtual hosting is a method for hosting multiple domain names on a single server. To successfully implement virtual hosting mechanism in 4D, a few requirements must be met.

1. No static home page assigned to the Web settings.



This will guarantee that the request to home page for each domain name is handled by developer inside the On Web Connection database method.

2. The On Web Connection or the methods that will be called through 4DACTION must include a code that checks for the host name so that it can respond appropriately.

Here is an example:

C_LONGINT($foundat_l)
C_TEXT($domainName_t)
ARRAY TEXT($httpHeaderNames_at;0)
ARRAY TEXT($httpHeaderValues_at;0)
WEB GET HTTP HEADER($httpHeaderNames_at;$httpHeaderValues_at)
$foundat_l:=Find in array($httpHeaderNames_at;"Host")
If ($foundat_l#-1)
  $domainName_t:=$httpHeaderValues_at{$foundat_l}
End if
Case of
  : ($domainName_t="www.technews.com")
    //
    // Handle all requests for www.technews.com
    //

  : ($domainName_t="www.inventnow.com")
    //
    // Handle all requests for www.inventnow.com
    //

  : ($domainName_t="www.dothetech.com")
    //
    // Handle all requests for www.dothetech.com
    //
End case