UPDATE SEPTEMBER 08, 2015: Yesterday I migrated all my websites from a GoDaddy legacy account to a 'Linux Hosting with cPanel' shared account. After site propagation I realized that none of my server side includes worked. The answer to this problem is to include the following line of code in each of your sites' .htaccess files:
AddHandler server-parsed .php .html .htm
written by RJ Wattenhofer
This article was written on April 17, 2013 utilizing the most current and tested approach to setting up and implementing the server side include command on your GoDaddy.com account. The information I provide may pertain to other hosting companies, but I have not personally tested it on their servers so I cannot vouch if it will indeed work outside the realm of GoDaddy. This tutorial is valid for GoDaddy customers on Linux servers and may or may not apply to Windows servers.
The first step is to create an .html test file to determine if you can run SSI on your server. Copy the following code into your text editor and save it as test.html:
<HTML> <TITLE>Test SSI</TITLE> <!–#config timefmt="%A" –> <!–#echo var="DATE_LOCAL" –> </HTML>
Upload this file to the server and check the path in your browser (ex. www.yourdomain/test.html). You should see a page with a single word that reads the current day of the week (ex. Sunday, Monday, etc).
If you see this then we have verified that you can run SSI and you may now delete the test file as it is no longer needed. Under GoDaddy Hosting Configuration 2.0 you will definitely see the day of the week. If you do not see this then you will have to contact your hosting company's customer service department to discuss the parameters of your specific hosting account.
The second step is decide on the location of your master code file. This file contains the code that you want to include in your page(s). You have a couple of choices for location, depending on what you are trying to accomplish:
1) Limited inclusion: This code is earmarked for inclusion in only one page or a few pages
in the same directory, or:
2) Global inclusion: This code is needed site-wide in pages located in many different directories.
If this code is to be used site-wide, you will now need to create a new directory on the server into which you will place the code files that you wish to include in your website page(s). I suggest placing the directory at root level, which is the top level (i.e. first tier) of directories within the root. If the code is to be used in the same directory as the website page(s) then do nothing for the moment.
You do not need to enable Server-Side Includes for HTML files via .htaccess if you are using GoDaddy. This is a configuration file that defines who or what is granted access to the files contained in a directory and allows the server to execute permissions to the HTML files that you want processed.
Since late 2011, this SSI access function has been enabled by default on Apache 2.2 and later. If you use any variations of the "Option Includes" command (you may have read you need this - not true any longer) in your existing .htaccess file you will get a "500-Internal Server Error".
In addition, you do not need to rename your file extensions .shtml. Happily, all your files may keep their existing extensions (.html, .htm, etc).
For those readers using a different hosting provider, I have included the proper syntax to be included in your .htaccess file:
DirectoryIndex index.shtml index.html AddType text/html .shtml AddHandler server-parsed .shtml Options Indexes FollowSymLinks Includes
You may have to experiment with different variations on the above code to get it to work properly, but at least you have an idea what to configure if you decide to do further research into the matter. Again, GoDaddy customers do not need to use the above code, as its function is set up by default.
Moving forward, we will now work on the master code file that contains the code we want included in our page(s). Open your text editor and create a text file with the extension .txt and name it whatever you prefer (i.e. code.txt).
We are making a .txt file rather than a standard .html file because if you do create an unnecessary .html file, your webpage will pull in all of the extra file markup:
<!DOCTYPE html> <html lang="en"> <head> <body> </body> </head>
This will end up giving you two of everything on your webpage. So we will avoid that by using our .txt file.
Place only the code needed in the text file (again, minus the above markup) and then upload the file to the proper directory, which would be either your new directory for global inclusion, or in the directory where the web pages are located that need SSI.
Finally, we include the command code that initiates the action. Open up the file/webpage that requires the new code. If the new text file is in the same directory as our page(s), then place the following code in the exact location where you want the new code to run:
If your text file is located in its own separate directory to be used globally, then insert this line of code:
Where you see the word DIRECTORY would be the exact name of your new directory, thus creating the proper file path. Under no circumstance place the following code as a precursor under the mistaken assumption that it is needed:
Using that code on the same page as your new code will definitely not work as originally intended and will cause problems. I mention this because you may have read somewhere that this command is required, which it is not, as GoDaddy servers no longer need it.
If you have done everything correctly then your webpage should now reflect the recent changes and your code should be running nicely. If you haven't, you will most likely see this alert: "[an error occurred while processing this directive]". If you see this, the culprit is probably the command code in your webpage not formatted properly. The code must be exact, including the empty space, as seen above.
Another issue is that, for some inexplicable reason, it may not like the first forward slash on the word /DIRECTORY/. Remove this and see if it now works correctly.
When you view the source code of your web page, you'll notice that the command code is hidden, instead replaced by the code from your master code file. If some mysterious empty P tags appear in your page file next to the command code, then delete them and wrap your new code in division tags.
Virtually any code can be used in a server side include, and there are some other nifty functions as well:
Today is <!--#echo var="DATE_LOCAL"-->
Which gives you this:
Today is June 26, 2017
This code will tell you the last time I was on this page messing around:
This file was last modified <!--#echo var="LAST_MODIFIED"-->
RESULT: This file was last modified September 21, 2016
Hopefully you have a much better understanding of implementing SSI after reading this tutorial. I wish you the best on your coding ventures.
~ RJ Wattenhofer, April 17, 2013