fix redirect loop bug

http://manage.dimagi.com/default.asp?49818#276361