Fix issue #1340 - Redirect loop on search

Fixed redirect loop which occurred on multi-word search or when search query contained special characters and the 'redirect ugly URL's' option was on.
I seem to have been a bit too zealous trying to escape unsafe $_SERVER variables before ;-)