Ever since moving NeoSmart Technologies to a Windows server, we've had one headache after the other dealing with various PHP scripts that included references to $_SERVER["REQUEST_URI"], and unfortunately, none of the "workarounds" or hacks provided on the internet work. Some of them are for Apache on Windows, and others work most of the time, but break the minute you introduce url rewriting or launch scripts as the default files in a directory.
REQUEST_URI for Windows is a must-install for absolutely anyone that uses IIS & PHP, no matter what software you run. It's free, it's one-hundred percent compatible with Apache's own REQUEST_URI, and best of all, it's guaranteed to work no matter what. REQUEST_URI for Windows gets whatever the user entered into the address bar - period. Nothing more, nothing less. And of course, you never have to modify a single script to make them work, this does all the work for you.
If you're still reading till this point, you're probably wondering where the code is. Unfortunately, it's not that simple. First, we make one assumption: this requires that you be the administrator/owner of the server you want to deploy this on. It's not nice, we know, but such functionality only comes from the very top - ISAPI filters. But that's not too bad, most people on shared hosts use LAMP servers, and most Windows server users either own or administrate their server anyway.
If you don't have administrative privileges, skip on ahead!
Requirements
- This ISAPI filter - to get the info we need (the free, lite version works just fine for our needs);
- NeoSmart Technologies' request_uri.inc;
- A modified httpd.conf.
- Download and install ISAPI_Rewrite, the (partially free) mod_rewrite imitation for IIS. All it takes is one click, it'll automatically setup everything for you and take care of installing the ISAPI filters.
- Download and extract request_uri.inc to the location of your php.ini (your PHP home).
- Open your PHP home directory (where php.ini is), and locate the following lines: [sourcecode language='java']auto_prepend_file = auto_append_file = [/sourcecode]and change them to [sourcecode language='java']auto_prepend_file = "c:/php/request_uri.inc" auto_append_file = [/sourcecode]Where "c:/php/" is replaced with the directory where you extracted request_uri.inc
- Open up Start | Programs | Helicon | ISAPI_Rewrite | Httpd.ini
- On a blank line at the beginning of the document ((Except when used along-side a Gallery2 install, in which case the Gallery2 rewrite definitions must preceed this since Gallery2 automatically attempts to compensate for IIS' broken
request_uri… which isn't broken anymore!)), copy and paste the following: [sourcecode language='java']# Defining $_SERVER['HTTP_REQUEST_URI'] RewriteCond %{URL} (.*) RewriteHeader REQUEST_URI: . %1 # End HTTP_REQUEST_URI [/sourcecode] - Open the IIS Admin Console, and restart the IIS service (or use the command prompt to do the same: iisreset.exe).
- You're done! Now any time a script calls up
$_SERVER["REQUEST_URI"], NeoSmart Technologies' script will dynamically update it to the real value, as if you weren't on a WIMP server!
With our Request_URI for Windows script, you don't have to ever modify another PHP script just to make it correctly detect the contents of REQUEST_URI - then discover it doesn't actually work. All NeoSmart-Technologies' code used in the process is released under the LGPL, so you can use it wherever you like without a problem.
If you don't have administrative rights on the machine in question, you can still use our request_uri.inc to a limited extent. It's not exactly 100% compatible, but it comes near it. Just put our file in the same directory as your script and add
[sourcecode language='php']require("request_uri.inc");[/sourcecode]at the top of your script - it might be enough for your needs.

request_uri.inc points to a .7z file
Yes, you have to
unzipextract it.This is one of the many enhancements/freebies in the make for WordPress users that we blogged about yesterday (though we promise the rest will be more WordPress-specific!)
NeoSmart Technologies will be switched over to this new system within a couple of hours, and we'll also publish guides on making WordPress work with pretty urls on IIS with the same engine used above.
Switch is complete, took a lot less than we'd anticipated. You'll notice that individual post's comment feeds (look in the sidebar) are working once more, and more obviously, incorrect permalinks now redirect once more as they did on our old server.
This very post is an example: http://neosmart.net/blog/?p=291 takes you to http://neosmart.net/blog/archives/291 — something that never would have been possible without our request_uri hack (on IIS that is).