Potential cookie fix in redirect

Since our SourceCodes differ so much I'm not sure if this fix will work with your code nor if this fix is optimal since it might remove a set path such as "/test/test/asdf" making it "/test/test"

If you could test it some it would be great!