Fix query handling for relative URLs