KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Redirecting URLs permanently
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: September 27, 2002
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Compatibility: 6.7 and later

As Web sites change and grow, it's common to move pages and other files to new addresses. When browsers and proxies request files at the out-of-date URL, the Web server can reply with the new address instead of sending an error. This process is called redirection and is achieved by sending an appropriate HTTP status code and a new URL in an HTTP response header field called Location. The browser or proxy use the updated location to make a new request with the correct address. This process is typically unnoticeable to end users, unlike the familiar 404 Page Not Found error.

The 4D command SEND HTTP REDIRECT performs a temporary redirection to a new URL. If the address has changed permanently, however, it is better to send a permanent redirection message. This can be done in 4D using the SET HTTP HEADER command, as shown below:

ARRAY TEXT(httpResponse_name_at;3)
ARRAY TEXT(httpResponse_value_at;3)

    `   If including X-VERSION and X-STATUS in the headers,
    `   they must always be the first and second items.
httpResponse_name_at{1}:="X-VERSION"
httpResponse_value_at{1}:="HTTP/1.0"


    `  Note: SEND HTTP REDIRECT sets the status code
to 302, Moved Temporarily:
httpResponse_name_at{2}:="X-STATUS"
httpResponse_value_at{2}:="301 Moved Permanently"



    `   Specify the new location of the requested item:
httpResponse_name_at{3}:="Location"
httpResponse_value_at{3}:="http://www.newurlhere.com/"


SET HTTP HEADER(httpResponse_name_at;httpResponse_value_at)

    `   Clear arrays now that they are not needed:
ARRAY TEXT(httpResponse_name_at;0)
ARRAY TEXT(httpResponse_value_at;0)

    `   Redirection responses have no contents apart
from the headers themselves.
    `   Send a blank string to force 4D to close the
request and send the headers.
SEND HTML TEXT("")