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:
- https://domain.tld/ is a site whose root is mapped to
C:\some_site_root
C:\some_site_root\mydir
is an existing physical directoryC:\some_site_root\mydir\some_cgi_script.pl
andC:\some_site_root\mydir\simple.html
are existing files- .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
Comments
Anonymous
August 18, 2005
Thank you for complete answer.Anonymous
June 11, 2010
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.Anonymous
July 10, 2015
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.