flash service

High_Performance_Web_Sites

Issue link: https://read.uberflip.com/i/1146286

Contents of this Issue

Navigation

Page 101 of 169

80 | Chapter 11: Rule 11: Avoid Redirects There are good reasons for sending a redirect when the trailing slash is missing: it allows autoindexing (going to the index.html by default) and makes it possible to retrieve URLs in the page that are relative to the current directory (e.g., logo.gif ). However, many popular web pages don't rely on autoindexing, instead relying on specific URLs and handlers. Additionally, URLs are often relative to the root and not to the current directory. Note that a redirect does not happen if the trailing slash is missing after the host- name. For example, http://www.yahoo.com does not generate a redirect. However, the resultant URL seen in your browser does contain the trailing slash: http://www. yahoo.com/. The automatic appearance of the trailing slash is caused because the browser must specify some path when it makes the GET request. If there is no path, as in http://www.yahoo.com, then it uses simply the document root (/ ): GET / HTTP/1.1 Sending a redirect when a trailing slash is missing is the default behavior for many web servers, including Apache. The Alias directive is an easy workaround. Another alter- native is to use the mod_rewrite module, but Alias is simpler. * The problem with the Astrology site could be resolved by adding the following to the Apache configuration: Alias /astrology /usr/local/apache/htdocs/astrology/index.html If you're using handlers in Apache 2.0, a cleaner solution is available in the form of the DirectorySlash directive (for more information, visit http://httpd.apache.org/docs/ 2.0/mod/mod_dir.html). Assuming there is a handler named astrologyhandler, the use of DirectorySlash would look as follows: DirectorySlash Off SetHandler astrologyhandler None of these alternatives solves the problem of finding URLs relative to the current directory, so the URLs of components in the page should be made relative to the root. Also, make sure you understand the order in which various modules are run (notably mod_dir and mod_autoindex) because using DirectorySlash this way could have security implications. In summary, if your web site contains directories and uses autoindexing, it is likely that users are suffering a redirect to reach the intended page. You can check your web logs to see how many 301 status codes were issued, which can help you deter- mine whether it is worthwhile to fix the missing trailing slash problem. * For more information about the Apache mod_rewrite module, visit http://httpd.apache.org/docs/1.3/mod/ mod_rewrite.html.

Articles in this issue

Links on this page

Archives of this issue

view archives of flash service - High_Performance_Web_Sites