100% Apache-Compliant REQUEST_URI for IIS and Windows!

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

  1. 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.
  2. Download and extract request_uri.inc to the location of your php.ini (your PHP home).
  3. 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

  4. 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:

    # Defining $_SERVER['HTTP_REQUEST_URI']
    RewriteCond %{URL} (.*)
    RewriteHeader REQUEST_URI: . %1
    # End HTTP_REQUEST_URI

  5. Open the IIS Admin Console, and restart the IIS service (or use the command prompt to do the same: iisreset.exe).
  6. 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.

  • Similar Posts

    Craving more? Here are some posts a vector similarity search turns up as being relevant or similar from our catalog you might also enjoy.
    1. Request_URI For IIS Updated with ISAPI_Rewrite 3 Support
    2. How To: Open Source + Windows + IIS... with Stability
    3. No More Downtime!
    4. Why is $_SERVER[] Considered a “Class?”
    5. Configuring JSP for IIS
  • 9 thoughts on “100% Apache-Compliant REQUEST_URI for IIS and Windows!

    1. 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.

    2. 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).

    3. Works like a charm !!!

      only included the .inc file, and all was good.

      nice to see 3 year old fixes still work on that F*ck*** they call IIS.
      why would you wanna rus IIS in the first place?

      Thanks again verry, verry much… kept me from rewritng the naviagtion of my site. saves me at least a day !!!

    4. Does this package still benefit me if I am installing PHP 5.3 Not Thread Safe on IIS with FastCGI engine?

      If yes please explain? And are there any additional tips I should know about?

    Leave a Reply

    Your email address will not be published. Required fields are marked *