Sunday, October 4, 2009

How to do rewrites in an IIS ISAPI

Note to self: If ever you need to do a rewrite in an IIS ISAPI Filter you just need to re-set the pHeaderInfo's url header. Something like this:

 
pHeaderInfo->GetHeader(pCtxt->m_pFC,
"url",strUrl.GetBuffer(dwUrlSize+1),&dwUrlSize);
strUrl.ReleaseBuffer();
strNewUrl = GET_REWRITE_FOR_URL(strUrl);
if ( strNewUrl.IsEmpty() == FALSE ) {
pHeaderInfo->SetHeader(pCtxt->m_pFC,
"url", (LPTSTR)(LPCTSTR)strNewUrl);
}
return SF_STATUS_REQ_NEXT_NOTIFICATION;

This is working in IIS4 and above.

Note that if you really need a good re-write/redirect filter for IIS you should look at IIRF ,but since it's not working for IIS4 i had to do this manually

3 comments:

  1. What's wrong with http://www.urlrewriting.net?

    Jenya.

    ReplyDelete
  2. non of the solutions on the web work for IIS4.

    ReplyDelete
  3. You are right.... There are still people who use IIS4?! It is running on NT4, right?

    ReplyDelete

[Due to much spam, comments are now moderated and will be posted after review]