Mike Volodarsky's blog

Formerly the core server PM for IIS 7.0 and ASP.NET, now I run LeanSentry.
UPDATES: New troubleshooting guide released! Fix IIS website hangs →

The latest on the FastCGI project and PHP support on IIS

Ever since the original release of FastCGI Tech Preview 1, and the Microsoft/Zend collaboration announcement to bring production-quality PHP to IIS, the FastCGI project has been steadily gaining momentum in the community.   With the release of Longhorn Server Beta 3, a number of hosters are beginning to offer FastCGI-powered PHP support on top of their IIS7 offerings, which is really when it gets exciting.

******************************************************

UPDATE (9/24/2007): The FastCGI Go-Live release for IIS6 and IIS5.1 is here!  Read about it and download it to start hosting your PHP applications today: http://mvolo.com/blogs/serverside/archive/2007/09/24/Deploy-your-PHP-applications-today-with-the-IIS-6-FastCGI-Go_2D00_Live-release_2100_.aspx

****************************************************** 

UPDATE (9/24/2007): The FastCGI Go-Live release for IIS6 and IIS5.1 is here!  Read about it and download it to start hosting your PHP applications today: http://mvolo.com/blogs/serverside/archive/2007/09/24/Deploy-your-PHP-applications-today-with-the-IIS-6-FastCGI-Go_2D00_Live-release_2100_.aspx

****************************************************** 

Since I’ve been away for a while wrapping up IIS7 core server and ASP.NET Integrated Pipeline work for Longhorn server,  I figured this would be a great time to check back in and give you an update on the FastCGI project.

FastCGI for IIS7 is now available out-of-the-box in Longhorn server
As you already knew, IIS FastCGI comes in two flavors: IIS7 module for Vista / Longhorn Server, and IIS5/IIS6 ISAPI for Windows XP / Windows 2003 Server.   Several months ago, we were given the approval to add IIS7 FastCGI into Windows, so starting with Longhorn Server Beta 3, IIS7 includes FastCGI support in the box! 

Powered by IIS7

This makes installing and trying out FastCGI in Longhorn SB3 a piece of cake.  If you haven’t downloaded Longorn SB3 already, be sure to check it out – it contains quite a bit of IIS7 improvements, especially around security, performance, and hosting support.  

 To get started, be sure to check out the step by step walkthrough for installing FastCGI in Longhorn SB3, and learning more about the internals.

If you are running Vista – you can download the Technical Preview 2 release of FastCGI for IIS7.  Of course, when Vista SP1 comes out, Vista’s IIS7 will also contain FastCGI in the box.


Unofficial update to out-of-band FastCGI for IIS6

If you are interested in running FastCGI on Windows XP or Windows Server 2003, or on Vista, then you should be using the latest out-of-band Technical Preview 2 release of FastCGI for IIS5/IIS6.

While we are still working on the Beta release for the IIS5/IIS6 version of FastCGI, we didn’t want to leave you hanging – so, if you are having any trouble with TP2, you can download the latest developer release of out-of-band FastCGI that fixes a few problems reported by the community since TP2’s release.

Just a note: this release has not had all of the internal testing as was done for TP2, so get it only if you are having problems.


PHP 5.2.2 released
Recently, Zend has released another point update to PHP, which is the second release containing fixes that make the PHP engine itself work better on Windows (many of these were found and fixed as part of the collaboration efforts between the IIS team and Zend, and the community feedback).
 

Download PHP 5.2.2 here.

This release, much like the PHP 5.2.1 before it, provides Windows non-thread-safe builds of PHP designed specifically for IIS FastCGI.   If you are intending to use FastCGI to power PHP, be sure to get these builds as they can provide up to 30% improvement in performance due to lack of thread synchronization overhead.

Stay tuned for more information as it develops.  Of course, please let us know if you are using FastCGI, and especially if you are running into any issues on IIS6 FastCGI forums and the IIS7 FastCGI forums.

Thanks,

Mike

 

Redirect requests to your application with the HttpRedirection module

Download: HttpRedirection_v1_source.zip

The HttpRedirection module allows you to configure regular expression-based rules that redirect clients from url A to url B using http redirection.

When clients make a request to your server, and the url matches one of the redirection rules you have configured, the server will respond with a redirection response, telling the client to go to your redirected url to complete the request.  It will look something like this (standard redirection response):

HTTP/1.1 302 Foundrn
Date: Thu, 24 May 2007 21:32:05 GMTrn
Location: /redirection/users/mike/rn

rn
<html><head><title>Object moved</title></head><body>rn
<h2>Object moved to <a href="/redirection/users/mike/">here</a>.</h2>rn
</body></html>rn

The Location response header will indicate the redirected url to which the client will automatically redirect.  Some older browsers that don’t support this behavior (I don’t know of any at this point) will see the hyperlink and the user will be able to manually click it to go to the new url.

Deploy the HttpRedirection module in your application


IIS5
: The module can only redirect requests made to content-types mapped to ASP.NET.
IIS6: Same as IIS5, unless you configure the IIS6 / ASP.NET 2.0 wildcard mapping support (see the
how-to in the LeechGuard post).  Then, this module will be able to provide redirection for all requests.
IIS7: In Integrated mode applications, this module will by default provide redirection for all requests. 

Setting it up is simple:

1.       Download the sample application, and use it
OR

1.       Drop the module assembly into /BIN

2.       Register the <httpRedirection> configuration section in your web.config file, and configure the desired redirection rules as shown in the example app.

Create HttpRedirection rules for your application

The rules can be expressed in the <httpRedirection> configuration section in your web.config file, and allow you to set the following:

matchUrl

The regular expression matching the incoming request urls.

redirectUrl

The url to redirect to, which can contain regular expression references to capture groups from the matchUrl, allowing you to insert parts of the original url into the new url.

urlPart (optional, defaults to PathAndQuery)

The part of the incoming url to match: the entire url, or just the path and querystring, or path only.  Use this to avoid writing regular expressions to match more of the url then you care about.

redirectType (optional, defaults to Temporary)

The type of redirection you want: temporary, permanent, or see other.

requestStage (optional, defaults to BeginRequest)

The stage of the request processing during which you want the redirection to take place.  Can be BeginRequest, PostAuthenticate, or PostAuthorize

The matchUrl and redirectUrl can contain special variables that expand to various request parameters, including:

·         {Protocol} – the protocol scheme of the url

·         {Hostname} – the hostname of the url

·         {Port} – the port of the url

·         {Path} – the absolute path of the url

·         {Query} – the querystring.  Also {Query:Param} for a value of the specific QS parameter.

·         {SV:Param} – the value of a specific server variable (can use this to get any request header)

·         {User} – the name of the authenticated user

·         {Culture} – the culture for this user

·         {AppPath} – the application path for the current application

·         {DirectoryPath} – the directory path segment of the url

·         {FilePath} – the file path segment of the url

(If you are using the “{“ symbol as part of the regular expression in either matchUrl or redirectUrl, escape it by using “{{“)

You can also configure the redirection module to append the original url in the querystring with the appendOriginalUrl parameter on the <httpRedirection> section, and keep track of the redirection depth so redirection loops can be broken by configuring the maxRedirects parameter.

Here are some example rules you can start with:

<!-- Redirect all requests to www.website.com to website.com -->

<addname="Hostname"urlPart="EntireUrl"matchUrl="^{Protocol}://www.(w+.com.+)"redirectUrl="{Protocol}://$1" />

<!-- Redirect to a localized version of the app -->

<addname="LocalizedApplication"urlPart="PathAndQuery"matchUrl="^{AppPath}/content/(.+)"redirectUrl="{AppPath}/content/{Culture}/$1" />

<!-- Redirect all HTTP requests to application to HTTPS -->

<addname="SSLRedirect"urlPart="EntireUrl"matchUrl="^http://(.+)"redirectUrl="https://$1" />

<!-- Redirect to the same url, placing the Referer http header in the querystring -->

<addname="PlaceRefererInQueryString_NoQuery"urlPart="PathAndQuery"matchUrl="^{Path}$"redirectUrl="{Path}?referrer={SV:HTTP_REFERER}" />

<addname="PlaceRefererInQueryString_WithQuery"urlPart="PathAndQuery"matchUrl="^{Path}?((?!referrer).*)$"redirectUrl="{Path}?referrer={SV:HTTP_REFERER}&amp;$1" />

<!-- Permanently redirect all requests to multiple product pages into a single product catalog with querystring -->

 

<!-- Permanently redirect all requests to multiple product pages into a single product catalog with querystring -->

<addname="ProductCatalog_NoQuery"urlPart="PathAndQuery"matchUrl="^{AppPath}/products/([^/]+).aspx$"redirectUrl="{AppPath}/products/catalog.aspx?productId=$1"redirectType="Permanent" />

<addname="ProductCatalog_WithQuery"urlPart="PathAndQuery"matchUrl="^{AppPath}/products/([^/]+).aspx{Query}$"redirectUrl="{AppPath}/products/catalog.aspx{Query}&amp;productId=$1"redirectType="Permanent" />

The current version is v1.0, released on May 24, 2007.

1.     Download the module and the sample application.

2.     Download the source code (this code is distributed under the Microsoft Permissive License).

Let me know if you are using it, and if you have any questions / suggestions / complaints by leaving comments.