Configuring Apache in Useful Ways
Note: Apache can be configured through its httpd.conf file and/or through an access control file (typically named ".htaccess") placed in directories. When you are experimenting with a server that you are running, you may use either method. When you are working on your FAS account, you can only use directives within access control files, since the Web server httpd.conf file is not under your control. The examples presented here will work with ".htaccess" files on
www.fas.harvard.edu. Remember that your ".htaccess" files must be "readable" by the web server.Also, note that
www.fas.harvard.edu runs Stronghold 2.4, which is based upon Apache 1.3.0. Some of the features you may see in the Apache documentation apply only to version 1.3.1 and higher.As always, reading the documentation is a good idea before asking questions:
Apache 1.3.4 Documentation:
http://www.courses.fas.harvard.edu/~cscie12/apache_manual/ (local copy)
Stronghold 2.4 Documentation:
http://www.fas.harvard.edu/stronghold-docs/
Customized Error Documents
ErrorDocument error-code {string|url}
http://www.apache.org/docs/mod/core.html#errordocumentErrorDocument 404 /~cscie12/response404.html
ErrorDocument 500 /~cscie12/response500.html
ErrorDocument 403 /~cscie12/response403.html
ErrorDocument 401 /~cscie12/response401.html
Expires HTTP Response Header
ExpiresActive On
ExpiresByType image/gif A2592000 # expire gifs in 30 days
ExpiresByType text/html A86400 # expire html in 1 day
http://www.apache.org/docs/mod/mod_expires.html
Arbitrary HTTP Response Headers
Header [set|append|add] header value
Header unset header
http://www.apache.org/docs/mod/mod_headers.html
Redirecting URLs
See the directives:
Redirect permanent /~cscie12/assign.html /~cscie12/assignments/
URL Rewriting Engine
http://www.apache.org/docs/mod/mod_rewrite.html http://www.engelschall.com/pw/apache/rewriteguide/We will see an example of how to redirect "Lynx" users to a text-only version of the site – but this module can do much, much more!
RewriteEngine On
RewriteBase /~cscie12
RewriteCond %{HTTP_USER_AGENT} ^Lynx
RewriteRule ^(index.html)?$ text/
Access Control and Authentication
Access control and authentication are covered in detail as part of the next section on security.