Ensure that your HttpModule is inserted in the web.config above the declaration for the SPRequest sharepoint http module, otherwise you'll always be redirected to the sharepoint error page.
When debugging your module you may come across an error message like Headers have already been written otherwise.
