SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

Rod Ward
SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

Calling all Regular Expression experts!

Apologies for this rather lengthy post, but if you can solve the following issue with some elegant regular expression code, you just might make a lot of current and future Moodle/IIS/SCORM users very happy.  Read on if you dare...

First I'll lay out the background to this issue (apologies to those that already know it), then I'll explain what I think we need to provide as a solution to finally get SCORM packages working reliably on IIS.

HISTORY: For years now, we have been seeing numerous posts in the SCORM forum (and other forums) from baffled Moodle users trying to get this wonderful LMS to work seamlessly with the IIS web server.  The complaints usually center around page not found (404) errors on combinations of files uploaded to Moodle that work perfectly anywhere else. Often those offering assistance comment that they have no issues playing the same content on their Moodle site running Apache server. 

Now we all know Moodle can work well on IIS, and it will play of almost any type. BUT, sadly it can tend to fail when you upload course files into your moodledata folder...IF...those files require other linked files in order to play. So for example, if you have an HTM file in your course that needs a linked Javascript or SWF file to play course content, will likely encounter issues with IIS....specifically page not found or 404 errors.  The files.php page digs out the requested HTM file, but then the browser goes looking for the other linked files in the same folder as files.php, not in the moodledata folder where the original HTM file resides!

The issue is due to the way that some pages in Moodle pass information about the URL address of another page by tacking this information on the end of a URL. (E.g. mypage.php?nextpage=/folder1/subfolder1/otherpage.php) Though a common enough technique in web development, this can prove problematic, especially for IIS. SCORM packages seem to be most affected by this issue because they often involve a complex cascade of pages calling other pages, passing arguments in links to play the content and communicate with the SCORM API on the LMS, etc, etc. Their complexity is their downfall in this case.

On Apache server, the issue often goes away as soon as you play with the Admin > Server > HTTP > Use Slash Arguments setting. But IIS 6 is unable to use slash arguments because Microsoft disabled this 'feature' as it was a well-known security hole exploited by hackers. (IIS 7 is rumoured to have options that allow it to operate safely again.)

About ISAPI Rewrite: The workaround successfully used by some Moodle-IIS users in various forum posts to fix IIS has been to install a small application called ISAPI Rewrite that intercepts the call to URLs on IIS and dynamically rewrites them into a more palatable format. This app is well known to webserver admins and used to implement redirects and/or improve search engine friendliness of websites. Once ISAPI Rewrite is installed on your webserver, you just create a new Web Service Extension in IIS Manager, point it to the ISAPI_Rewrite.dll, make a copy of the httpd.ini file from the C:\Program Files\Helicon\ISAPI_Rewrite and copy it into your Moodle root directory (so that any code there only affects Moodle), and finally add a rewrite rule. The rewrite rule quoted in many Moodle forum posts as pulling off the fix is a line of code (a regular expression) that looks like this:

RewriteRule (.*?\.php)(\/.+) $1\?file=$2 [N,I]

This normally works and cures the slash arguments issue on IIS,...if your content only involves a single HTM file calling other files (e.g. an HTM linking out to images, javascript, or SWF files). Happy days...almost.

However, it doesn't seem to work for most SCORM packages, and I believe the reason is that SCORMs involve much more complex interactions and argument passing between pages that this little rewrite rule doesn't allow for. Under SCORM, the rewrite rule can encounter not just one set of arguments but several.

I'm currently using Moodle 1.82 on IIS 6.0 and ISAPI Rewrite with the rule shown above.   I can get any type of content to play,...except SCORM. Perusing IIS server logs I've found that the URL which is failing on my box looks like this:


Notice that there are not one but two question marks in this URL? I think this is why IIS is falling over and if we could tweak the rewrite rule to allow for this, we might just be able to get SCORMs (at least those created by Captivate) to play on IIS. We may even need multiple rules customised to a given SCORM implementation to get them working.

Now since I don't know how to write regular there anyone out there that can oblige?? If so, and we can put this issue to bed, we may have eliminated a major source of frustration for many Moodle users.

Suggestions please...?

Average of ratings: -
Rod Ward
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

Just to add more fuel to the fire.

I've discovered that IIS, even with a rewrite rule cannot handle any extra arguments being added to the query string. Even a single ? on the end will break it. Apache has no such problems.

See the graphic below. This is the same HTM and Javascript file set up in Moodle on Apache and Moodle on IIS (middle and lower). You can add anything you like on the end of the URL and Apache will still serve up the testpage.htm. On IIS it will only work if there are no additional arguments added.  SCORM packages would almost always do this. IIS only gives you one throw at adding arguments to a URL. Moodle's use of file.php to call files from moodledata folders by passing in the file URL as an argument would appear to be using that throw as far as IIS is concerned.

Average of ratings: -
Picture of John Isner
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite
Hi Rod,
I have a basic question:

What is a reference to file.php doing inside a SCORM?

I thought SCORMs were supposed to be platform independent. file.php is a Moodle thing. So this SCORM is not conformant because it links to a page using a mechanism that is only available on Moodle. The reference was probably created by copy/paste of a URL. If so, all bets are off.

Am I wrong?

Average of ratings: -
Rod Ward
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

Hi John,

I think you misunderstand. The reference to file.php is not inside the SCORM. File.php is shown in the link because that's how Moodle fetch content out of moodledata course folders to serve up.  If you look at a typical web server trace of what happens when a SCORM is accessed in Moodle, you see a series of links like this, all beginning with file.php, followed by it's argument containing the path to each of the files inside the SCORM.

SCORM packages have to be inside the moodledata folder for them to communicate with Moodle's SCORM API properly. You cannot have the SCORM located elsewhere on the webserver, or on another webserver, because the API communication breaks down and scores don't get passed.

So the issue we're trying to solve here is not due to a problem in my SCORM package. The issue is due to the way that Moodle has implemented file.php,...specifically because it uses URL arguments to pass data about the pathway to a file (as shown in my example).  However, if that file also happens to have arguments on the end of it (such as ?SCORM_API=0.2&SCORM_TYPE=0 from my example) then IIS throws a fit. If there is even so much as one ? or / after the name of the file in the argument being passed by file.php, IIS cannot handle it. Apache just laughs and says: "No problem!" (Long live open source.)

So, does anybody have ideas about how to get over this issue?

I'm beginning to wonder if the only way to fix it is to refactor the files.php code to pass file path info via some other means.

Average of ratings: -
Rod Ward
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

A little more info has come to light that should make this now ridiculously easy for anyone familiar with Regular Expressions (which sadly I am not).

It turns out that the whole issue comes down to the question mark tacked onto the end of the filename of the file being called by files.php.

If we can modify the rewrite rule to dynamically change this question mark to an ampersand, everything works! The files in the SCORM package are served up by IIS (via files.php), the content plays, and the SCORM score values are passed to the SCORM API. I've been able to verify this by manually changing where the character gets added in the original SCORM javascript code.

So is there an easy way to change this regular expression...

RewriteRule (.*?\.php)(\/.+) $1\?file=$2 [N,I] that it turns the extra question mark found in some cases (such as SCORMs) into an ampersand instead?

We just need to ensure it only does it under these specific conditions so that it doesn't break other pages unrelated to the use of file.php.

Any takers?

Average of ratings: -
Rod Ward
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

I think I may have found a solution to this now.

Here is the code I have in my httpd.ini file inside the Moodle root folder:

# Matches any URL with slashed arguments and adds ?file= before args
RewriteRule (.*?file\.php)(\/.+) $1\?file=$2 [N,I]
# Finds any cases of doubled up ? and changes the second one to &
RewriteRule ((.*)([?]+)(.*))([?]+)(.*) $1&$6 [I]

You must use the rules in the order shown.

The first rule is a slightly modified version of the one previously used. It changes a slashed argument URL into one using ?files= so that IIS can accept it. I had to limit the scope to just the file.php file because it fouled up SCORM playback if you had already unzipped the package and were pointing directly at the imsmanifest.xml file. Don't know why, it just did.

The second rule finds any cases of URLs that have two instances of ? characters and changes the second one to an ampersand (&). But it has to follow the first rule otherwise with slashed arguments on in Moodle it won't find any cases of doubled up ?s.

With this now in place, I have IIS playing SCORMs in Moodle that wouldn't previously play...and...they are all reporting scores to the database. Yeehaa!!

Anybody that can see an issue with this or knows of a better way to solve it is welcome to chime in. For example...There may be other pages in Moodle that use slashed arguments. If so, I'll probably need to add a version of the first rule to cover each one.

I'm going back to bed now...bye.

Average of ratings: -
Picture of Sankar R
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

Hi Rod Ward

we are using moolde in iis 5.1 we need to play a scorm course in that. we got into the problem of isapi rewrite rule. can u tell me the steps how to activate it and rewritable rule for SCORM http.ini Could u please help me?

Thanks, Sankar .R

Average of ratings: -
Picture of Edward Bethel
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite
OK Rod

Now I have a question for you. I'm running a site using Apache 1.3 on webhosting service and I'm having exactly the type of problem you describe here. I describe it at length here

basically, I get the "no input file specified" whenever I try to view a file I've uploaded to moodle (including SCORMs). I tried turning off slash arguments - the file then loads, but without being able to call any other files - no css, no images etc. If I click on any links in the page I get the 404 error (predictably because the link is searching for the file in the moodle root directory instead of the moodledata directory.

Will the code you posted work here too? I don't have any experience writing code, but I'm willing to give it a shot as I've tried just about everything else.

The link to my forum post details all the things I've tried.

Thanks for whatever help you can give me

Average of ratings: -
Picture of Fred Weiss
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

I have implemented the ISAPI Rewrite as described above and turned off slash argumets all my IMS and scorm and  all seem to work happily.

However, I have now found a side affect that with slash arguments off profile images than do not display.  I am wondering if there is a further isapi rewrite rule that could be implemented to fix this as the profile images us pix.php to display.

Average of ratings: -
Picture of Fred Weiss
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite
The rules in this forum fixed by edit profile images broken gifs without upsetting any links in my IMS imports.
Average of ratings: -
Picture of Luis Batista
Re: SCORM, IIS 6, Slash Arguments, and ISAPI Rewrite

I have problems to run ISAPI_Rewrite on IIS 6.0 (on Windows Server 2003).

I run this step's:
1) Download ISAPI_Rewrite v3.0 (from Helicon Tech), the Free version
2) Install ISAPI_Rewrite.msi
3) On "C:\Program Files\Helicon\ISAPI_Rewrite3", edit the "httpd.conf" to add Rewrite Rules
4) and Restart IIS

Back to Moodle, call the SCORM module, on the left appear the topics, and the central zone get a "404 Not Found" error!!!
I copy the scorm content on moodledata and put on the moodle website to test if scorm are correct and all wroks fine.

The problem is Rewrite execution!

Can help me to put this to work?

Best Regards,
Average of ratings: -