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

  • 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.
  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: [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
  4. Open up Start | Programs | Helicon | ISAPI_Rewrite | Httpd.ini
  5. 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]
  6. Open the IIS Admin Console, and restart the IIS service (or use the command prompt to do the same: iisreset.exe).
  7. 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.



Leave a Reply  •  About to Ask for Help?  •  Subscribe to Our Feed

26 Responses to “ 100% Apache-Compliant REQUEST_URI for IIS and Windows! ”


  1. 1Denis de BernardyNov. 17th, 2006 at 5:15 pm

    request_uri.inc points to a .7z file

  2. 2Computer GuruNov. 17th, 2006 at 5:22 pm

    Yes, you have to unzip extract it.

    Download and extract request_uri.inc…
  3. 3Computer GuruNov. 17th, 2006 at 8:13 pm

    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.

  4. 4Computer GuruNov. 17th, 2006 at 8:53 pm

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

  1. 1 links for 2006-11-18 « sunburntkamel Pingback on Nov. 18th, 2006 at 4:30 am
  2. 1 [wp-hackers] REQUEST_URI for IIS/Windows Perfected Pingback on Nov. 18th, 2006 at 8:03 am
  3. 1 PHP: Predefined Variables - Manual Pingback on Nov. 19th, 2006 at 11:09 pm
  4. 1 PHP: 기 언 변수 - Manual Pingback on Nov. 20th, 2006 at 5:50 am
  5. 1 dzone.com - upcoming links Pingback on Nov. 20th, 2006 at 9:00 pm
  6. 1 PHP: Predefined Variables - Manual Pingback on Nov. 21st, 2006 at 12:01 pm
  7. 1 PHP: Predefined Variables - Manual Pingback on Nov. 21st, 2006 at 11:20 pm
  8. 1 PHP: Vordefinierte Variablen - Manual Pingback on Nov. 29th, 2006 at 9:35 am
  9. 1 PHP: Variables Predefinidas - Manual Pingback on Nov. 30th, 2006 at 6:38 pm
  10. 1 :: View topic - REQUEST_URI Pingback on Dec. 1st, 2006 at 9:27 am
  11. 1 PHP: Variáveis predefinidas - Manual Pingback on Dec. 14th, 2006 at 8:43 am
  12. 1 Nabble - Replacing TinyMCE with Xinha Pingback on Dec. 14th, 2006 at 10:08 am
  13. 1 PHP: Variables prédéfinies - Manual Pingback on Dec. 15th, 2006 at 3:29 pm
  14. 1 PHP: 定義済の変数 - Manual Pingback on Dec. 18th, 2006 at 8:27 am
  15. 1 PHP: Variabili predefinite - Manual Pingback on Jan. 8th, 2007 at 12:48 am
  16. 1 Dokeos Forum :: View topic - IIS $_SERVER['REQUEST_URI'] Pingback on Jan. 24th, 2007 at 5:58 pm
  17. 1 WebSpam raus! - .NET Pingback on Mar. 18th, 2007 at 12:27 pm
  18. 1 Download Request_URI for IIS 1.0 - NeoSmart Technologies Pingback on Mar. 26th, 2007 at 12:51 pm
  19. 1 Forum of the spiders and crawlers tracking script CrawlTrack / login to blank page. Pingback on Apr. 6th, 2007 at 9:06 pm
  20. 1 IIS hates REQUEST_URI and Simple PHP Flat-File Call : Carbon Pingback on May. 9th, 2007 at 6:30 pm
  21. 1 IIS hates REQUEST_URI and Simple PHP Flat-File Call at Adolescent Adulthood Pingback on May. 12th, 2007 at 6:27 am
  22. 1 AWSOM.org = Artist Website Setup Options Markup » Blog Archive » Further Information For Windows IIS users and Pixgallery Pingback on Jan. 28th, 2008 at 4:50 pm

Leave a Reply