๐Ÿ“š General & Other

Stripping a Trailing Slash Without Breaking the Root

removes a final slash and gets the root case wrong. Several other cases need care too.

sed 's|/$||' removes a final slash and gets the root case wrong. Several other cases need care too.

The root must keep its slash

https://example.com/ becomes https://example.com, which is a valid host but no longer a complete URL with a path. Any rule operating on the whole string cannot distinguish this from a normal path ending in a slash โ€” the check has to know where the path begins.

Query strings and fragments come after the path

/page/?a=1 does not end in a slash, so a string-level rule misses it entirely while a path-level rule handles it correctly. The slash to remove is the last character of the path component, not of the string.

Directory versus file semantics

On some servers /docs and /docs/ resolve differently, with the second treated as a directory index. Normalising the recorded URL does not change what the server does, so verify the chosen form actually returns 200 rather than a redirect before standardising a whole dataset on it.

Parse, modify, reassemble

As with every URL operation, the reliable approach is to parse the URL, change the path component, and rebuild. String manipulation handles the common case and quietly mangles the rest.

Try it: Remove Trailing Slash from URLs on SeoWolf's Notepad.