Logo

Maarten Balliauw {blog}

ASP.NET, ASP.NET MVC, Windows Azure, PHP, ...

About the author

Maarten Balliauw is currently employed as a Technical Evangelist at JetBrains. His interests are mainly web applications developed in ASP.NET (C#) or PHP and the Windows Azure cloud platform.
More about me More about me
Send mail E-mail me


ASP.NET MVC Quickly Pro NuGet Subscribe to my RSS feed Follow me on Twitter! View Maarten Balliauw's profile on LinkedIn
Maarten Balliauw - MVP - Most Valuable Professional
Maarten Balliauw - ASPInsider

Search

Archive

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright Maarten Balliauw 2013


Use Zend Framework on IIS

A while ago, I was experimenting with the Zend Framework. At first, I tried running a small sample on top of IIS, but unfortunately, that did not work... On Apache, it worked like a charm. Very nice, but what do you do when your site runs on an IIS machine?

I started experimenting. First of all, I found out that Zend Framework also accepts URL's like http://localhost/index.php/controller/action/ as well as http://localhost/controller/action/. The first one is really handy! The only thing you have to do is to feed index.php the right query string and you're up and running. Changing all your URL's from /x/y to index.php/x/y should do the trick.

But this does not look pretty in my browser. I don't want the index.php in between!

Searching Google, I found some ISAPI filters that provide URL rewriting, but none of them are free. As a Belgian, I don't like spending my money when results are not guaranteed. Luckily, another idea popped up in my mind: let's fool IIS! Everybody using IIS knows that you can customize your 404 (page not found) error page. What about trapping all 404's to a central page, that can dispatch the request to my index.php file? A schematic overview:

I assume  you are familiar with configuring IIS and its error pages. All you have to do is save this file as RewriteController.aspx, and point your 404 error page there.

Now go ahead and try! The RewriteController.aspx changes the internal request in IIS from http://localhost/index/index (default action) to http://localhost/index.php/index/index. The address bar of your browser stays the same thoug. Subsequent requests are all routed this way, which means you can keep using your path's without index.php in between.

Some remarks:

  • If Zend Framework always tries the no route action, try using Zend_Controller_RewriteRouter instead of the default Zend_Controller_Router.
  • RewriteController.aspx can be rewritten in another scripting language too, but ASP.NET provides some nice shorthands to server variables...
  • Routing all errors trough RewriteController.aspx is probably a small performance bottleneck. Not noteworthy, but on high-traffic websites I expect this to slow things down
  • Another best practice on the Zend Framework is to redirect the noRoute to some sort of a 404 page

Categories: General | PHP

Comments (7) -

Troglo Spain |

Wednesday, May 07, 2008 10:56 AM

Troglo

The link to the file RewriteController.aspx doesn´t work
www.balliauw.be/.../RewriteController.aspx.txt

It´s a pity because I thik your method is pretty nice and clean

Norman@"smokeless cigarette" Philippines |

Monday, March 07, 2011 1:15 AM

Norman@"smokeless cigarette"

Smoke?!! Why use a cigarette that has an annoying smell,when you could have the better one no ash, no tar, no smell for more inquiries please visit our website;

<a href="www.smokelesssensations.com">smokeless cigarettes</a>

maartenba Belgium |

Wednesday, May 07, 2008 11:05 AM

maartenba

Seems like I lost that one in converting my blog from PHP to ASP.NET... But have a look at blog.maartenballiauw.be/.../...ss-like-syntax.aspx, it might also be a solution.

Piotr Blasiak Sweden |

Sunday, August 03, 2008 7:39 PM

Piotr Blasiak

There is now actually a way to do this for free, if you have IIS 7.0. I wrote a small tutorial in my blog:

blog.qiui.com/.../

Hope this helps some people. I had to figure this out by myself as the module if pretty new Smile

Dave Green United Kingdom |

Friday, November 07, 2008 12:34 PM

Dave Green

Hello,

I link to the example file RewriteController.aspx is broken.

Can you send it to me, or fix the link.

Thanks very much.

maartenba Belgium |

Friday, November 07, 2008 12:51 PM

maartenba

Dave check the comments on top. Link is unfortunately lost Frown

Football Tips United States |

Thursday, March 03, 2011 1:16 PM

Football Tips

Is the link broken? But anyway it is still a very great post !

Pingbacks and trackbacks (2)+

Comments are closed