Post navigation

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);

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:

auto_prepend_file =
auto_append_file =

and change them to

auto_prepend_file = "c:/php/request_uri.inc"
auto_append_file =

Where “c:/php/” is replaced with the directory where you extracted request_uri.inc

The following step is only for users of ISAPI_Rewrite 2.x
If you’re using ISAPI_Rewrite 3.x, skip ahead to step 5!

Open up Start | Programs | Helicon | ISAPI_Rewrite | Httpd.ini

On a blank line at the beginning of the document, copy and paste the following:

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 won’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

require("request_uri.inc");

to the top of your script – it just might be enough for your needs.

If you face any problems getting this to work, the support forums are only a click away.

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.