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


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 http://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 http://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 ?


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:


    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.


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


    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. http://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:

http://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
http://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.


Comments (3)

  1. August says:

    Thank you for complete answer.

  2. Bryton Lee says:

    I'm Chinese, my English is poor, and I don't konwn if you can follow what I say.

    I have read the rfc3875 , In my opinion PATH_INFO is a argment for the CGI script , the argment may a pathname or other, for example "a.txt is" PATH_INFO,  SCRIPT_NAME is "test.php", so when CGI run test.php , It may have a argment is "a.txt", but "a.txt" is a virtual path, so It need to translate to physical path, so we need a variable PATH_TRANSLATED.

  3. Laurie says:

    PATH_INFO is indeed the decoded extra-path, however the article author has confused extra-path with script-path. PATH_INFO is everything following the script path and preceding the query (which is absent).

    In the example, the script-path (decoding to SCRIPT_NAME) is /mydir/some_cgi_script.pl, but the extra-path (decoding to PATH_INFO) is empty.

    The server path that corresponds to the PATH_INFO, if any, is administrator defined, but the mapped path yields PATH_TRANSLATED.

Skip to main content