G2 Short URLs on IIS revisited
|
mgrant
![]()
Joined: 2004-08-17
Posts: 100 |
Posted: Wed, 2004-09-01 22:46
|
|
Ok I think that I finally got short URLs working in G2 with IIS. Here are some of the steps required (note that I had to change some code in the GalleryUrlGenerator.class) First a little about the environment. OS: Windows Server 2003 Standard In my PHP.INI I first needed to set the following: 1) cgi.force_redirect = 0 Without these values I either got errors or did not get a value for PATH_INFO. At this point the test URL in the site admin page seemed to work. However, when I set Use Short URLs to YES I could no longer navigate to any page except the main gallery page. Furthermore all thumnails were missing. Clicking on a thumnail simply reloaded the main page. Here's where I needed to modify the G2 code: In modeuls/core/classes/GalleryUrlGenerator.class I see that the following _SERVER variables are expected: REQUEST_URI (absent) I think that the problem is that when the full URL is build it is built as: <protocol>://<HTTP_HOST><SCRIPT_NAME> In my case this means that if I enter: http://localhost/gallery2/main.php/view/album1 I will always end up with a URL that is: http://localhost/gallery2/main.php That's because none of the variables above include the PATH_INFO data. As I understand it that's the stuff that comes after the script name. Here's the section of code I modified to make it work for me. I suspect that this might cause it to break for others though especially if SCRIPT_NAME normally returns the PATH_INFO also. I'm not adept or experienced enough to know how to tell for sure though. Here is my change. /**
* Return the complete current URL
*
* @return string the current URL
*/
function getCurrentUrl() {
global $gallery;
if (!empty($_SERVER['REQUEST_URI'])) {
$path = $_SERVER['REQUEST_URI'];
} else if (!empty($_SERVER['SCRIPT_NAME'])) {
$path = $_SERVER['SCRIPT_NAME'];
}
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
$protocol = 'https';
} else {
$protocol = 'http';
}
/*
* Added this to allow ShortURL formats to work properly on IIS6 with
* PHP4
*/
if (isset($_SERVER['PATH_INFO'])) {
$pathinfo = $_SERVER['PATH_INFO'];
} else {
$pathinfo = '';
}
return sprintf('%s://%s%s%s',
$protocol,
$this->getCurrentDomain(),
$path,
$pathinfo);
}
//End of my changes
/**
* Return the current server domain
* @return string the host name
*/
function getCurrentDomain() {
if (isset($_SERVER['HTTP_X_FORWARDED_SERVER'])) {
return $_SERVER['HTTP_X_FORWARDED_SERVER'];
} else {
return $_SERVER['HTTP_HOST'];
}
}I'm curious if most others have a defined REQUEST_URI that includes the path info? I'm also curious if anyone has thoughts on why REQUEST_URI is not defined in my environment? It is also worth noting that setting AllowPathInfoForScriptMappings to True causes it to fail with the error "no input file". I suggest removing the note about using AllowPathInfoForScriptMappings as it will probably only cause confusion. Thanks, -mg[/code] |
|
| Login or register to post comments |


Posts: 100
I've just finished testing a few more things and here's what I've found.
1. When using PHP in ISAPI mode I only get page not found (HTTP - 404) errors when using "slashargs". (i.e. http://<server>/gallery2/main.php/view/album01).
2. Using CGI "slashargs" seem to work OK.
3. IIS doesn't define REQUEST_URI (or PHP doesn't pick it up?)
4. Gallery doesn't query the PATH_INFO (I'm assuming that would be part of REQUEST_URI?)
5. The following versions of PHP/Windows/IIS have been tested and confirmed to work OK.
5.0.1/2003/6
4.3.9RC2/2003/6
4.3.9RC1/2003/6
4.3.8/2003/6
4.3.7/2003/6
4.3.7/XPPro/5
I vaguely recall having seen "slashargs" URLs work with PHP in ISAPI mode but I've been unable to duplicate. FWIW, my starting point is whether I can open http://localhost/phpinfo.php/arg1
In no recent case that I've tried have I needed to set AllowPathInfoForScriptMappings=True.
-mg
Posts: 6019
Great work, mgrant. I've created a bug for us to update getCurrentUrl() with your patch.
Posts: 100
The GalleryURLGeneratorClass has changed some since I first discovered how to get ShortURLs working in IIS.
Here is my new version of the fix (my additions are in bold):
Also, please remove the reference to AllowPathInfoForScriptMapping from the site admin page. I think it will only be confusing to most users. In all of my succesful tests I have not had to set it.
Thanks,
-mg
Posts: 6019
Done! It's history.
Posts: 328
mgrant, I have IIS5.1 and yesterday haven't had that much time to test, but on my quick try, I couldn't make PHP work in CGI mode. I followed the instructions on PHP.net. I setup the "php.exe" as handler for .php, I did granted the permission for IUSR_machine to read/execute php.exe and its parent directories, but trying a simple test.php page ended up with 400 errors from IIS.
Do you have some tip on how to make this work?
I also noted that on ISAPI, PHP 5.0.1 wasn't able to process path-info like test.php/test. It returned an error. You mentioned it works? Is this also IIS-version dependant?
Posts: 100
Ernst,
I'm no expert here but there are a couple of things that I had to change in my PHP.INI to get things working with CGI mode.
1) cgi.force_redirect = 0
2) cgi.fix_pathinfo=1
3) make sure doc_root is commented out
Also, if you're using PHP5 you should substitute php-cgi.exe in place of php.exe.
See if these make a difference for you.
Thanks,
-mg
Posts: 328
mgrant, I was trying it with PHP 4.3.8, and had made these changes in php.ini (as suggested by someone in the comments of the manual page on IIS-install at php.net) but to no avail. Still, I haven't tried with much attention, so it might be just some easy thing I missed. Will try to get more on that this weekend.
I have explored the source-code of php4isapi.c and php5isapi.c and noticed that the change patch mentioned in the php's bug report was incorporated in php5isapi.c since the first release (beta) of PHP5, but never in the php4isapi.c (I have just checked 4.3.9RC3 that just came out).
There are some php4isapi.dll that have the patch applied at ftp://ftp.muze.nl/pub/ariadne/win/iis/, but only for older versions of PHP4. But maybe the 4.3.6 dll will work on 4.3.8, who knows?
Anyway, my intention now is to gather as much information as possible about this matter and document it somewhere. How different php versions behave at different IIS revisions and SAPI's.
Posts: 8598
There don't appear to be any unit tests relating specifically to short urls.. let me do something about that, then I'll put in your patch.
Posts: 8598
No unit test for parseCurrentUrl either? Who wrote this thing? :wink:
mgrant, so for IIS you get SCRIPT_NAME + PATH_INFO instead of the whole thing in REQUEST_URI, right? I'm writing the unit tests to try each of those scenarios.
Posts: 6019
*Ahem*. :oops:
Thanks for picking up my slack
Posts: 8598
Ok, unit tests and GalleryUrlGenerator updated.
mgrant, please get the latest and run the unit tests / test out short urls. Let us know how it goes.. thanks for your help on this!
Posts: 100
When I run PHP in CGI mode there is no REQUEST_URI. SCRIPT_NAME + PATH_INFO is one way to achieve the same result but there are other variables that may also give the same result. I don't know the CGI spec to know for sure what is the best thing to use.
I chose SCRIPT_NAME + PATH_INFO because SCRIPT_NAME was already there as a failover if REQUEST_URI was not defined. Only problem is for shortURLs to work you also need the PATH_INFO otherwise you cant navigate anywhere except the main page. So I check to see if PATH_INFO is defined and if so just tack it onto SCRIPT_NAME. Does the trick nicely for me.
I've been modifying GalleryURLGenerator each time I install and I've not seen a problem yet.
However, now that PHP5 in ISAPI mode is working more reliably with G2 that has become my main test environment. It appears to provide more complete (and perhaps more accurate) variables. REQUEST_URI is defined and works properly in PHP5 without the modifications I made.
Thanks,
-mg
Posts: 100
I just updated from CVS and re-ran the phpunit tests using PHP 4.3.9RC3 in CGI mode. I cannot run any phpunit tests since the page fails with an error:
I workaround this by commenting out the security.inc include in /lib/tools/phpunit/index.php (don't know why but it seems to work for me).
Once that's done I'm getting critical failures in some earlier tests that prevent some of the tests from being executed so I ran a filtered set of tests where filter=url and this is what I get:
Posts: 8598
My changes haven't made it to anonymous cvs yet; try again a bit later. You'll see new tests testshorturls and testparsecurrenturl.
Posts: 100
Perhaps with the recent changes this will be unimportant but it would be nice if the test url in the site admin page could be a more accurate indication of whether shortURLs work. Since I got "slashargs" working on PHP that test URL has always worked despite the fact that shortURLs were still broken. In fact, for some time I had assumed that short URLs were working because the test URL worked.
Thanks,
-mg
Posts: 328
mgrant, I think the idea of that "test" is to see if the Path-info is supported by the webserver. If it is, gallery somehow (when we have nailed down all possible variations) will have to be able to work with it.
Having the test actually make gallery do some work to check if it worked would be a possibility, we'll take a look if this is worth it.
Posts: 6019
I'm not sure how to improve that test. Can you provide me with a link that *doesn't* work when that test link does?