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;
- 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:
# Defining $_SERVER['HTTP_REQUEST_URI'] RewriteCond %{URL} (.*) RewriteHeader REQUEST_URI: . %1 # End HTTP_REQUEST_URI
- 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.
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).
Good job!!! Works perfectly.
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 !!!
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?
No, you’re good to go. The NTS builds are fine for FastCGI.
Thanks Man ….
You Saved My Life ….
Keep it up ….