Rewrite fix issue #33

This is a rewrite of pull request (https://github.com/EllisLab/CodeIgniter/pull/794) from @MidnightHack
Related issue is #33