What is PATH_TRANSLATED?

PATH_TRANSLATED is one of the most frequently misunderstood server variables, as this following question illustrates...

Question:

Hi David !

I have some problem with using function SERVER_CONTEXT->GetServerVariable(.......)

all info query i make in HttpFilterProc with SF_NOTIFY_AUTHENTICATION enabled

i need obtain 'PATH_TRANSLATED' server variable. all fork fine if I request some like https://domain.tld/mydir/some_cgi_script.pl

PATH_TRANSLATED - contain full path to this file ('c:\some_site_root\mydir\some_cgi_script.pl') and e.t.c.

but if i request https://domain.tld/mydir/simple.html PATH_TRANSLATED contain just 'c:\some_site_root' - that's all, no 'mydir' in path and no file name.

Why this happens ? or i'm dooing some wrong. maby exists diff. -> request cgi or request html file ?

Answer:

I suspect you are trying to obtain the full physical filename referenced by the virtual URL of the request being authenticated.

Through experimentation, you are guessing that PATH_TRANSLATED is supposed to return the full physical filename to you, but unfortunately, your guess is incorrect. According to CGI 1.1 Specification:

  • PATH_INFO

    The extra path information, as given by the client. In other words, scripts can be accessed by their virtual pathname, followed by extra information at the end of this path. The extra information is sent as PATH_INFO. This information should be decoded by the server if it comes from a URL before it is passed to the CGI script.

  • PATH_TRANSLATED

    The server provides a translated version of PATH_INFO, which takes the path and does any virtual-to-physical mapping to it.

  • SCRIPT_NAME

    A virtual path to the script being executed, used for self-referencing URLs.

As you can see, PATH_TRANSLATED is NOT defined as the "full path to the file" specified by the URL. It is a virtual-to-physical translation of PATH_INFO. And PATH_INFO is the "extra path information" at the end of the CGI script name.

Show me the Annotated Example...

Let me use your examples to illustrate the point. Based on your description, this is your server configuration:

  1. https://domain.tld/ is a site whose root is mapped to C:\some_site_root
  2. C:\some_site_root\mydir is an existing physical directory
  3. C:\some_site_root\mydir\some_cgi_script.pl and C:\some_site_root\mydir\simple.html are existing files
  4. .pl extension has an Application Mapping to C:\cgi-bin\perl.exe

For the following URLs, this is the expected behavior according to CGI 1.1 specification for the server variables PATH_INFO, PATH_TRANSLATED, and SCRIPT_NAME:

Request URL PATH_INFO PATH_TRANSLATED SCRIPT_NAME
https://domain.tld/mydir/some_cgi_script.pl /mydir/some_cgi_script.pl C:\some_site_root\mydir\some_cgi_script.pl /mydir/some_cgi_script.pl
https://domain.tld/mydir/simple.html C:\some_site_root /mydir/simple.html

Notice that since PATH_INFO for the script "/mydir/simple.html" is empty-string, by definition the virtual-to-physical mapping (aka PATH_TRANSLATED) would be for "/" which would be C:\some_site_root. This is the by-design behavior that you observed.

Now, on IIS6, we added a new server variable, SCRIPT_TRANSLATED, which is the virtual-to-physical mapping of SCRIPT_NAME. It is probably what you are looking for. Prior to IIS6, you will have to calculate and generate this yourself, and PATH_TRANSLATED is not it.

//David