Skip to content

Apache and Trailing Slashes

When you create a URL that points to a directory, the proper way to form the URL is with a trailing slash, signifying to the web server that you are asking for the index (or default file) of a directory, as opposed to asking for a specific file. When you don't include a trailing slash, the web server first looks for a file with the name you asked for, then when it doesn't find a file it checks to see if there is a directory by that name. If the web server locates the directory it then sends your browser a 301 response telling it that the resource it has requested has moved to a new URL (which includes the trailing slash). Your browser then has to make another request with the trailing slash so that the server will serve the content you are looking for.

For this reason, it's good practice to always include a trailing slash when you create a URL that points to a directory. It saves the browser and the server from unnecessary processing time and from making extra requests.

Depending on how Apache has been set up, web servers do not always try to resolve the directory name. This can result in either 500 internal server errors or 404 “Not Found” errors on your web site. To avoid this, always build your URL's correctly and ensure links use the trailing slash.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Topic: Site Management
Tagged as: Apache, indexes, processing time, slashes, web servers

Share on FriendFeed