Using ISAPI Rewrite 3 with Gallery 2

Categories:

Gallery 2 has always had very good support for generating user friendly URL's using the URL Rewrite module, and is one of very few PHP apps which supported this feature on IIS out of the box. This was done using ISAPI Rewrite 2 from Helicontech, however the ball game changed with ISAPI Rewrite 3 as its rules syntax changed to the same as that used in Apache's mod_rewrite module. This meant that the old ISAPI Rewrite 2 style rules used by Gallery 2 no longer applied, and as Gallery 2 gives you no other option but to use these old rules when using ISAPI Rewrite on IIS you were left in a bit of a stalemate. In this article we'll look at a workaround which enables you to use Gallery 2 using ISAPI Rewrite 3.

In order to get Gallery 2 to use ISAPI Rewrite 3 on your IIS server you need to perform two steps;

  • Patch the server detection routines in Gallery 2 so you are able to select Apache mod_rewrite as you URL Rewrite engine.
  • Patch your Gallery 2 config file with some code to enable the REQUEST_URI functionality on IIS to work as required.

So lets take a look.

First, open up the modules/rewrite/SetupRewrite.inc file in you Gallery 2 installation with your favourite text editor and locate the following code which should be on line 188;

    $serverTag = GalleryUtilities::getServerVar('SERVER_SOFTWARE');
    if (stristr($serverTag, 'apache') !== false) {
$SetupRewrite['server'] = 'APACHE';
    } else if (stristr($serverTag, 'iis') !== false) {
$SetupRewrite['server'] = 'IIS';

Simple comment out these lines like this;

//     $serverTag = GalleryUtilities::getServerVar('SERVER_SOFTWARE');
//     if (stristr($serverTag, 'apache') !== false) {
// $SetupRewrite['server'] = 'APACHE';
//     } //else if (stristr($serverTag, 'iis') !== false) {
// $SetupRewrite['server'] = 'IIS';

Save this and that is the first step complete.

The second step is even easier and just involves posting the following code into your config.php (anywhere between the PHP tags) file in the root directory of your Gallery 2 install.

// Isapi_Rewrite 3.x
if (isset($_SERVER['HTTP_X_REWRITE_URL'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
}

Save this and that is the second step complete.

The only thing left to do now is to install the URL Rewrite module for Gallery 2, and when you do this you should see you are able to select mod_rewrite which is usually restricted to Apache users. Select this and run through the config and you should now be able to use Gallery 2 with ISAPI Rewrite 3.

As always if you have any comments or feedback about this article, please feel free to post them here. If you require any specific help with your environment please post your questions in the forums.

Average rating
(1 vote)

Comments

Anonymous's picture

It's not working for me - my

It's not working for me - my URL rewrite page still shows only options for IIS. I even fiddled with which lines are commented out - I have no experience in PHP, but wouldn't you comment it out like this?

else {
    $SetupRewrite['bootstrap'] = 1;
    $SetupRewrite['server'] = 'UNKNOWN';
    $serverTag = GalleryUtilities::getServerVar('SERVER_SOFTWARE');
//     if (stristr($serverTag, 'apache') !== false) {
$SetupRewrite['server'] = 'APACHE';
//     }
// else if (stristr($serverTag, 'iis') !== false) {
// $SetupRewrite['server'] = 'IIS';
//     }
}

Anonymous's picture

OK, it works, just note that

OK, it works, just note that you have to uninstall the plugin then reinstall it to get the new settings to take effect. Thanks for the pointers!

Anonymous's picture

Hi, i get this error Message

Hi, i get this error Message after activating mod rewrite, what could be wrong?

Error (ERROR_CONFIGURATION_REQUIRED) : 15

    * in modules\rewrite\module.inc at line 145 (gallerycoreapi::error)
    * in modules\core\PluginCallback.inc at line 180 (rewritemodule::activate)
    * in modules\core\PluginCallback.inc at line 67 (plugincallbackview::handlecallback)
    * in main.php at line 450 (plugincallbackview::renderimmediate)
    * in main.php at line 104
    * in main.php at line 88

System Information
Gallery version 2.3
PHP version 4.4.3 isapi
Webserver Microsoft-IIS/6.0
Database mysqlt 5.0.27-community-nt
Toolkits SquareThumb, Gd
Operating system Windows NT 5.2 build 3790
Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7

Brashquido's picture

What version of ISAPI

What version of ISAPI Rewrite are you using (full or free)? Is the HTTP_X_REWRITE_URL variable set correctly? You can check this using the phpinfo function.

----------------
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

Hi, its

Hi, its ISAPI_Rewrite3_0062_x64 Full

In phpinfo i found this, but i dont know if ist correct:

_SERVER["HTTP_X_REWRITE_URL"] /galerie/lib/support/index.php?phpinfo

Brashquido's picture

I can't seem to reproduce

I can't seem to reproduce the error, mind you I am using PHP 5.2.9-1. Is there any particular reason you are using PHP 4.4.3? That release is over 2 years old now, plus PHP 4 is no longer supported by php.net. I'll have another go tonight, but it might be worth looking at upgrading to PHP 5 at some stage.

----------------
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

I used 4.4.3 because the

I used 4.4.3 because the performance with Gallery2 was much better. But now i tried 5.2.0 (it's installed by plesk) an get the same Errors.
I think i should update to 5.2.9. (but i read that its not so easy with plesk.)
Could this be the problem?

Error Detail -
Error (ERROR_CONFIGURATION_REQUIRED) : 15
in modules\rewrite\module.inc at line 145 (GalleryCoreApi::error)
in modules\core\PluginCallback.inc at line 180 (RewriteModule::activate)
in modules\core\PluginCallback.inc at line 67 (PluginCallbackView::handleCallback)
in main.php at line 450 (PluginCallbackView::renderImmediate)
in main.php at line 104
in main.php at line 88
System Information
Gallery version  2.3 
PHP version  5.2.0 cgi-fcgi 
Webserver  Microsoft-IIS/6.0 
Database  mysqlt 5.0.27-community-nt 
Toolkits  SquareThumb, Gd 
Operating system  Windows NT 5.2 build 3790 
Browser  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; .NET CLR 1.1.4322) 


Error (ERROR_CONFIGURATION_REQUIRED) : 15
in modules\rewrite\module.inc at line 145 (GalleryCoreApi::error)
in modules\core\PluginCallback.inc at line 180 (RewriteModule::activate)
in modules\core\PluginCallback.inc at line 67 (PluginCallbackView::handleCallback)
in main.php at line 450 (PluginCallbackView::renderImmediate)
in main.php at line 104
in main.php at line 88
System Information
Gallery version  2.3 
PHP version  5.2.0 isapi 
Webserver  Microsoft-IIS/6.0 
Database  mysqlt 5.0.27-community-nt 
Toolkits  SquareThumb, Gd 
Operating system  Windows NT 5.2 build 3790 
Browser  Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; GTB5; .NET CLR 2.0.50727; .NET CLR 1.1.4322) 

Anonymous's picture

Very strange thing: i've

Very strange thing: i've updated to the new PHP-Version, but the error is still the same

Error Detail  -
Error (ERROR_CONFIGURATION_REQUIRED) : 15

    * in modules\rewrite\module.inc at line 145 (GalleryCoreApi::error)
    * in modules\core\PluginCallback.inc at line 180 (RewriteModule::activate)
    * in modules\core\PluginCallback.inc at line 67 (PluginCallbackView::handleCallback)
    * in main.php at line 450 (PluginCallbackView::renderImmediate)
    * in main.php at line 104
    * in main.php at line 88

System Information
Gallery version 2.3
PHP version 5.2.9-1 isapi
Webserver Microsoft-IIS/6.0
Database mysqlt 5.0.27-community-nt
Toolkits SquareThumb, Gd
Operating system Windows NT 5.2 build 3790
Browser Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7

Brashquido's picture

Restore and try again

I've installed Gallery 2.3 on my IIS 5.1 machine using ISAPI Rewrite 3 Lite and PHP 5.2.9-1 ISAPI and have not been able to reproduce this error. After following the guide above I am able to select mod_rewrite in Gallery 2, and after ensuring the .htaccess rules were being picked up by ISAPI Rewrite it all works as expected.

I'm wondering if your SetupRewrite.inc file was patched correctly? I suggest restoring SetupRewrite.inc and trying again. The only thing being changed in this guide is removing Gallery's ability to detect what web server is being used, resulting in Gallery presenting all rewrite options rather than just the ones thought suitable for your web server.
----------------
Dominic Ryan
4 x Microsoft IIS MVP, MCSE, MCSA
IIS Aid owner/webmaster

Anonymous's picture

I tried to make this on a

I tried to make this on a new, clean Gallery 2,3 installation.
It worked, and i saw the mod_rewrite configuration-page.
after some trying with the test links i found out that i had some problems with the rights of the .htaccess files.
After fixing that i saw the green success, but it crashed again.
After that, i get the same error like before :(
And now i'am not able to see the mod_rewrite configuration-page. Its simply skipped after installing the short rurl module.
I only see the activation-link, and after clicking this one the error appears.

So i cleaned the complete cache, copied the complete installation files, run an upgrade-setup, did the same again, but i never more saw the mod_rewrite configuration-page. Everytime the same error.
I dont know if Gallery this anywhere.