Issue link: https://read.uberflip.com/i/1146286
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:

