Parse URI more reliably