Whenever I think I finally figured out one of the cryptic configuration settings Apache laughs at me yet again with a nice big fat "Gotcha sucka!".
I've struggled through all sorts of bullshit to get scriptmapping to work with Apache. So today I'm putting the final touches on an installation routine that installs a set of scriptmaps. I've tested this setup routine with a few different scenarios and it's worked just fine. Now though for the actual final installation in the application I need this to work and just won't cooperate and I'm starting to see double as I can't figure out why.
After a lot of tinkering I finally figured out that the order of the ScriptAliasMatch and the AddType extension mapping is vital. So if I have this set up like this:
Alias /wconnect/ "C:/Program Files/Apache2.2/htdocs/wconnect/"
<directory "C:/Program Files/Apache2.2/htdocs/wconnect/">
DirectoryIndex default.htm
Options ExecCGI
AddHandler webconnection-isapi-handler dll
AddType application/webconnection-scriptmap-wc .ap .wwd .wc .wcs .wcsx .wwsoap .blog .pho .wwr .wwt
Action application/webconnection-scriptmap-wc "/wconnect/bin/wc.dll"
</directory>
ScriptAliasMatch (?i)^/wconnect/.*.(ap|wwd|wc|wcs|wcsx|wwsoap|blog|pho|wwr|wwt)$"C:\Program Files\Apache2.2\htdocs\wconnect\bin\wc.dll"
it doesn't work. Apparently when AddType is hit and no matching file is found on disk for the request Apache gives a NOT FOUND response and never moves any further down the hierarchy for looking for files.
Now I can move the ScriptAlias before the <directory> tag and the AddType and then it DOES work in firing my request at least:
Alias /wconnect/ "C:/Program Files/Apache2.2/htdocs/wconnect/"
ScriptAliasMatch (?i)^/wconnect/.*.(ap|wwd|wc|wcs|wcsx|wwsoap|blog|pho|wwr|wwt)$"C:\Program Files\Apache2.2\htdocs\wconnect\bin\wc.dll"
<directory "C:/Program Files/Apache2.2/htdocs/wconnect/">
DirectoryIndex default.htm
Options ExecCGI
AddHandler webconnection-isapi-handler dll
AddType application/webconnection-scriptmap-wc .ap .wwd .wc .wcs .wcsx .wwsoap .blog .pho .wwr .wwt
Action application/webconnection-scriptmap-wc "/wconnect/bin/wc.dll"
</directory>
The problem with this arrangement is that in the latter scenario the ScriptAliasMatch is ALWAYS used and the real problem is that Apache blows away the physical path in the process.
When a ScriptAliasMatch is applied the physical path is mapped to the Executable (ie. c:\program files\...\bin\wconnect\wc.dll) and the original reference to the file is lost. There's a LOGICAL PATH, but no physical path that can establish the original file on disk that was actually requested.
AddType routed requests on the other correctly return the physical path for a file, but because of the way this ordering works
So...
Really what this all comes down to is consistency. What I need is to be able to ALWAYS retrieve the Physical Path.
I already have a custom Module that fixes up various Apache'isms to work more like IIS. However, I have not been able to figure out how to do Path Mapping with the Apache APIs. My code is based off Mod_ISAPI and in an ISAPI extension you can typically call ServerSupportFunction and ask for HSE_MAP_PATH to do a virtual to physical mapping. Unfortunately Apache returns the physical path to the DLL as above which for IIS based ISAPI is the wrong thing (IIS returns the original mapped path regardless of whether the request was remapped to a different handler).
In ASP.NET or ASP this sort of thing would be as easy as Server.MapPath( Request.ServerVariables["Logical_Path"]).
I suspect Apache has something similar in its core API but after digging through reams of source I'm not having any luck finding it.
Any Apache experts out there? Is there a way to do path mapping even if the requested file doesn't exist?
Looking around it also seems that there's next to no documentation on the Apache internal server APIs. Nor is there a public forum - only mailing lists. Is there some place where Apache developers that deal with lower level issues hang out? If so they're not easy to find <s>...
Any help greatly appreciated...
Other Posts you might also like