Using Server-side Includes
Task:
My entire site layout uses the same header and footer, so I want to be able to update the look by updating a file, instead of every page.
How to do it:
If you use the same HTML coding in several places on your Web pages, you'll want to use includes. Includes can simplify your web page maintenance tasks by saving you from retyping the included code wherever it occurs. If you ever want to change the code, you then only have to edit it in one location instead of finding every occurrence and having to change it on each individual page.
Follow these steps:
- Open an HTML editor, like Microsoft SharePoint Designer, and create a web page
with everything that you want to duplicate on multiple web pages.
- Save this file as includefile.html, depending upon
your choice.
- If you'd like to include the file in .html pages, create a .htaccess file with the following line:
AddType text/x-server-parsed-html html htm
Then to include the includefile.html, insert the following code in to every .html page that you want.
<!--#include virtual="/~user name/includefile.html" --> - If you'd like to include the file in PHP scripts, insert either one of the following lines:
<? require ("includefile.html"); ?>
or
<? include ("includefile.html"); ?>
They work the same except that require ignores PHP conditional statements, so it will be called every time even if you put it inside a loop. - To accomplish the same effect on the OIT Windows web
server (fp.auburn.edu), check out Dynamic Web Templates and Master Pages in Microsoft
SharePoint Designer.
- If you'd like to include the file in .asp or .aspx files on the OIT Windows web
server (fp.auburn.edu), insert either one of the following lines:
<!--#include virtual="includefile.html"-->
or
<!--#include file="includefile.html"-->Note: Server-side includes do NOT work in .htm or .html files on the Windows server, only in .asp and .aspx files.
- Save all files and upload them to the same directory via FTP.
Change the bold words to the appropriate path of the includefile.html.Note: Includes on the Mallard server do not work for files named with extensions .htm or .HTM, so be sure to name the files with .html or .HTML
Note: You can have PHP code in the include file, but name it with a .php extension.
Troubleshooting: Require function creates an endless loop
How-to: Redirect files and directories
