You will always have to rewrite.
Always.
Sometimes sooner, sometimes later.
Plan on it. Design so that you can rewrite. Practice Late Binding and the other SOLID principles.
And rewrite as soon as you possibly can to keep the technical debt down.
Remember.
You will always have to rewrite.
Get it over with as quickly as possible. A hack is just debt.