THE GITHTML FIELD GUIDE
Fix links to filenames containing question marks or hashes
Characters such as question marks and hashes have structural meanings in URLs, so a filename containing them needs appropriate percent encoding in its path segment. Distinguish the filename from a query or fragment before editing the link. Avoid double encoding and verify the exact destination with a small test case.
Identify the specific failure
A link intended for report#1.html can instead refer to a fragment named 1.html in a different resource. The text looks plausible, but URL parsing assigns it another meaning. Similar confusion occurs when a question mark is interpreted as the start of a query.
Make a narrow correction
Encode the reserved character that belongs to the filename, not the entire URL indiscriminately. Preserve path separators and any real fragment you intend to use. Simpler filenames can reduce future mistakes when renaming is practical and existing links are updated deliberately.
- Identify which characters belong to the filename and which delimit URL components.
- Encode reserved characters within the relevant path segment once.
- Verify the resulting file and fragment independently before replacing shared links.
<a href="report%231.html">Report number 1</a>Parse a filename and section target as separate components
Suppose the intended file is report#1.html and the desired section inside it is findings. The path needs to represent the filename's hash character as %23, while a real fragment separator still precedes findings. The resulting link is report%231.html#findings. Encoding both hashes the same way would turn the section target into part of the path; leaving both unencoded would cause the first hash to begin the fragment too early. Write down the intended filename and identifier separately before assembling the URL.
A percent sign introduces another trap. If an already encoded %23 is encoded again, it can become %2523, changing what the recipient resolves. Avoid repeatedly processing a complete URL through a routine intended for one path component. Likewise, do not encode the slash that genuinely separates directories when the goal is only to protect a reserved character inside a filename. A simple diagnostic uses one file with an uncomplicated name and one with the troublesome character, both linked from the same directory.
Confirm the exact stored filename, including case and extension, before interpreting an encoding change as successful. A renamed file may have broken old references even if the new link works. When you control the document collection, straightforward filenames can reduce ambiguity, but renaming is a separate maintenance decision that requires updating inbound links. For a received artifact you do not own, report the intended path, the parsed destination, and the observed result. Do not silently rewrite a query parameter or fragment that the original publisher actually intended to preserve.
Verify the repaired artifact
Test the resource and any section fragment separately. A successful file load does not establish that the fragment identifier exists.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.