Southern New Jersey Overlook

head_left_image

When To Use A Trailing Slash in URLs and Why

"You think you use the correct URL for your pages? Are you sure?"

Because of an unresolvable issue with a previous web hosting service provider, I had moved one of my web sites to a new service provider.  Since I was staying within a Linux based web hosting environment and my web pages were essentially basic HTML pages, I was able to make the transfer and be up and running within an hour. 

It took another 24 or more hours for the new domain location to be replicated and found through the Internet, but everything seemed to work as expected. 

However, when typing in domain addresses that referenced subdirectories without a trailing (or final or ending) slash ("/"), the resulting message indicated that my requested page could not be found.  But when I accessed the paged in the subdirectory (folder) adding a slash or when I accessed any page in the subdirectoy directly or from links on another page, I could view the page with no problem.

For example, I have subdirectory where I store text versions of U.S. documents such as the Declaration of Independence, the Constitution of the United States and Bill of Rights.  The URL is:  http://www.lawrenceyerkes.com/USdocs/.

When I typed it without the slash,  http://www.lawrenceyerkes.com/USdocs, it failed to find the corresponding web page.  However, http://www.lawrenceyerkes.com/USdocs/ worked, as well as the default page that it returned: http://www.lawrenceyerkes.com/USdocs/index.html.

It had worked as expected using any of the URL's cited above in the previous and I had not made any changes to the original web pages.  So what was causing this issue with the ending slash of URLs?


Here are a couple of links that explain why and when to use the slash at the end of the URL...

Slash, Slash, Slash
Final Slash In PathNames (see subheading in article)


That explains why and when using the trailing slash is important.  However, it does not explain why my web site responded properly in one environment and not in the other.   In both cases, they were Apache web servers.  So the results should have been identical. 

Here are a couple links explaining problem and how to resolve it...

Using a Trailing Slash In Linking (forum)
Apache URL (1.3) FAQ - Why does accessing directories only work when I include the trailing "/"?
   (Note: This is not the most current version of Apache, but it was still valid information which resolved my situation.)

The Apache FAQ identified the issue as caused by one of two situations. In my case it was a problem with the "Alias" directive in the Apache httpd.conf file.  However, getting the tech. support people to acknowledge that the problem was on their end was not easy.  I first had to "humor" them by temporarily removing .htaccess files and repeatedly reemphasising that I had no special scripting that could be causing this condition.  Finally, after getting a high level technician who went step-by-step over my logic for resolving problem, they finally agreed that problem was on their end with a simple Apache setting.  A change request was authorized and next day all was well.



Copyright 2008 by Lawrence Yerkes. All Rights Reserved.

Comments

This blog does not allow anonymous comments