Updated regex for cookie rewrite to support the case when the domain attribute is last.
Added tests for cookie rewriting.