Fix issue in handling SCRIPT_NAME during dispatch and provide tests to cover it