Include a Trailing Slash on Directory URLs

Including a trailing slash on a directory URL will decrease page load time because it reduces the number of times the browser has to access the web server.

Example

If you create a directory on the server named “/news” which contains several html files, the server will also expect that folder to contain the default index.html file so it will look like this:

http://www.domain/news/index.html

The default file may also be named index.htm, default.html or homepage.html.

So if you tried to access http://www.domain/news you would get http://www.domain/news/index.html instead.

Explanation

When you reference the “/news” directory can put an extra load on your Web server because the web browser isn’t sure whether this is a directory on a Web server or a file residing on the server.

The Solution

Adding a trailing slash to the directory URL will allow the browser to serve the correct file after a single request from the server.

Your directory URL should look like this:

http://www.domain/news/

Adding the “/” reduces the load on your Web server by removing an unnecessary page request. This reduces the load time of every page being served.

Search Engine Optimization Benefits

If you ever had to switch to another coding language you would not have to change the directory URLs because they end with
the trailing slash ie news/.

If you changed your site from pages ending in .html to pages ending in .php you would not have to change the directory structure.

Search engine spiders will still see the same directory.

If you had not used the trailing slash they may see two different files
ie
http://www.domain/news/index.html
http://www.domain/news/index.php

You would then have to create a 301 permanent redirect in your .htaccess file to remedy this situation.

Conclusion

Creating the correct directory structure during the building of your web site will help you avoid problems later should you decide to use another technology. It will also cause you site to load faster and be search engine friendly.

Resources

http://www.alistapart.com/articles/slashforward/

Speak Your Mind

*