How to get Umbraco to handle requests for non .aspx files (IIS integrated pipeline mode)?

3.3k views Asked by At

I'm trying to get the 301 URL Tracker package for Umbraco to work to my likings.

My goal is to be able to map the old URLs (from another CMS) to the new Umbraco URLs. In my specific situation, the old site is PHP based and therefore use the .php file extension (http://example.net/test.php -> http://example.net/test/) - but it could be any non .aspx extension (asp, png and so on). The problem is that Umbraco is not handling request for .php files. It works perfectly for .aspx and directories (extensionless URLs).

I have tried various things for getting this to work. Before I go any further, I should note that the Application Pool is in integrated mode and .NET 4.0.

I kind of got it to work by defining a custom error in the web.config:

<customErrors defaultRedirect="not-exists.aspx" />

This triggers the handlers defined in NotFoundHandlers in the Umbraco config file 404handlers.config. But has the side effect of returning a 302 Found header, before the 301 URL Tracker kicks in and handles the 301 redirect. And this is just a big SEO "no no".

I then tried to explicitly create a HTTP handler module for .php files. I successfully got the System.Web.UI.PageHandlerFactory module to handle the request for the .php file. But this does not invoke any of the NotFoundHandlers in Umbraco.

As I understand the integrated pipeline in IIS 7, all the modules registered should try to handle the request (http://stackoverflow.com/questions/3765317/how-to-catch-non-aspx-files-with-a-http-module). But perhaps somebody can enlighten me on this subject?

Others are also experiencing the difficulties in getting this configuration to work: http://our.umbraco.org/projects/developer-tools/301-moved-permanently/feedback/7271-when-the-old-pages-are-not-from-umbraco

What am I missing in getting Umbraco to handle request for non .aspx files in integrated pipeline mode?

2

There are 2 answers

4
Jamie Howarth On BEST ANSWER

If you are already running under Integrated Pipeline mode then the included UrlRewriting.net module should pick up requests automatically. Simply add:

<add name="phptoaspx"
     virtualUrl="^~/(.*).php"
     rewriteUrlParameter="ExcludeFromClientQueryString"
     destinationUrl="/$1.aspx"
     ignoreCase="true" />

to your /config/UrlRewriting.config file, and all should be well.

P.S. You should not be using a customError handler to handle SEO 301/302'ing content. This can be a massive headache in terms of maintainability - please trust me on this, I tried this once when I was a junior .NET dev!

1
Brent On

I am not familiar with Umbraco, but believe this is what you are looking for http://blogs.iis.net/ruslany/archive/2008/09/30/wildcard-script-mapping-and-iis-7-integrated-pipeline.aspx

Of course you'll have to add your own rewrite rules... so this only gets you half way.