|Server Side Includes|
I am using a hosted server, and trying to set up some includes on my site... i have done this with PHP on a linux server but not with HTML on a Win server..
Server: Win 2003 Enterprise Server
Pages are HTML.
i created an includes folder.
i created: nav.shtml
Per my server notes in the Cpanel it says: "Required SSI filename extensions: .shtml"
in my index.html page i used the line:
and other various tries... what am i missing?
can i not use html pages, do they have to be .asp pages to call the include?
I think you need to use index.shtml
The .shtml alerts your web server to parse that file differently than static HTML files.
Unless you have another include in the included file, you probably want to use:
Yes, you have the html/shtml backwards. .shtml is for the calling page, .html is for the called page. Actually, the called page can have whatever extension you want. I typically use .ssi, for example.
Also, if you put this code into your .htaccess file, then it doesn't matter whether your pages end with .shtml or .html:
AddHandler server-parsed .html
All of the above works for Apache web servers, but I assume it'll work for Windows, too.
The included file can be pretty much anything. <strong>However, the space before --> is extremely important.</strong>
<!--#include virtual="includes/nav.html" --> (in this case)
<!--#include virtual="includes/nav.txt" -->
<img src="<!--#include virtual="/images/some-image.gif" -->" alt="img">
<!--#include virtual="/cgi-bin/some-script.cgi" -->
What's important about the space before the "-->"? I've never included that space, and I've never had any problems...that I know of.
I can't even remember, all I recall is battling it one day and the space was what fixed it. One of those things you learn and forget about **why.**
Closest I found was this [w3u.net], (mods, nix the link if inappropriate) in reference to using echo:
|When you forget to leave a space before the closing SSI command HTML tag (-->), or when you add a space between the hash sign (#) and the SSI command (<!--# echo), nothing works, and you get that silly and ever-so-helpful error message ["an error occurred while processing this directive"]. |
If you note all the examples [httpd.apache.org], they have spaces.
Okay. But it's worked for me 100% of the time without the space, for years, so I think I'll likely keep doing it that way.
The space may be optional on some systems and mandatory on others. Since it is harmless, it's probably best to include it.
kaled nails it -- there are lots of technical areas where many systems now recover from common errors, but it's still best not to make them in the first place.