Skip to content

Trailing slash added to directories

All shared web hosting servers automatically add a trailing slash to requests for directories. For example:

  • https://example.com/directory redirects to https://example.com/directory/
  • https://example.com/2024/05/30/your-new-post redirects to https://example.com/2024/05/30/your-new-post/

This behavior (DirectorySlash On) cannot be modified on shared hosting. If you need to change it, you would need a cloud vps.

There are security and usability reasons for this on LiteSpeed/Apache:

  • Ensures the user requests the canonical URL of the resource
  • Allows mod_autoindex to function correctly with proper relative paths
  • DirectoryIndex is only evaluated for directories requested with a trailing slash
  • Relative URL references inside HTML pages resolve correctly