Site Administration Page 5 - Getting More Out Of Apache (Part 1) |
The next item on today's agenda involves something called "server-side includes", or SSI. Very simply, server-side includes are sets of instructions which enable Web servers to display data contained in server-side variables (server date and time, file currently in use, and so on). SSI also allows you to include external text files in your HTML pages - this comes in handy when you need to add a common header and footer to every HTML page. Adding support for server-side includes is again a matter of tweaking the Apache configuration file, "httpd.conf". By default, the server root is not configured to parse documents containing SSI instructions. In order to enable this support, you need to add the keyword to the <Directory> directive - it should look something like this: Next, you need to tell the server to recognize SSI files - these typically have the file extension ".shtml". In order to do this, add the following lines to the configuration file: Restart Apache for the changes to take effect.{mospagebreak title=Hello, World!} With that done, it's time to take see how server-parsed HTML files work. Create the following simple file, and save it as "hello.shtml". Now, when you point your browser to this page (via the Web server), you should see something like this Thus, the SSI directive allows you to obtain the name of the current document without you - the document author - having to explicitly specify it. SSI also allows you to display the size and last modification time of the current file - take a look! And the output would be: And you can also display the current server time, as illustrated below: Finally, SSI also allows you to separate common elements of your Web pages into separate files, and include these files on each and every page. For example, if I have a copyright notice that is to be displayed on each and every page, I could place it in a file named "footer.txt" and then create HTML pages which looked like this: Now, each time a page like the one above is requested from the Web server, Apache will automatically include the contents of the file "footer.txt" in the appropriate place. The final page might look something like this: Be warned, however, that extensive use of SSI can affect Web server performance, since the server has to first parse the file before sending it to the client browser - so use it judiciously. Detailed information on SSI can be obtained from the SSI resources at http://httpd.apache.org/docs/howto/ssi.html And that's about it for this time. Come back for the second part of this article, where I'll be discussing URL rewriting, user authentication and a few other tricks.
blog comments powered by Disqus |