Hello,
I was hoping someone could help me figure out why my html include was not working. In a previous thread, a while ago, I was told one can include html from another file using the following syntax: <!–#include virtual=“pathToFile.html” –>
Is that I am trying to use html includes in the following, and much simpler example, but the point is that they don’t seem to be working.
I have an index.html, which has the following syntax and a live copy is up here:
<!Doctype HTML>
<html lang="en">
<head>
<title>Red bg on no script</title>
<!--#include virtual="include.html" -->
</head>
<body>
<h1>Heading</h1>
<p>Paragraph</p>
</body>
</html>
and the file it includes is up here and the contents of that file is:
What happens if you change the file extension to .shtml as in index.shtml
Basically, you have to be sure that your server is set up to process SSI, then you have to tell it to look for includes by using the correct file extension.
A nicer solution (IMHO) is to use PHP includes, but your pages need to have a .php extension (well, you can avoid that, but there’s not much point generally). Anyhow, try what imaginekitty suggests anyway, so you at least know what the issue is.
But isn’t it already looking for the correct file-extension ?
The suggestion you made applies to the file calling the include (index.html in my example) not the file to be included (include.html), right? @ralph_m: What does IMHO mean?
wait, a file using php includes can not have a .php extension?
Wait, what? ?? If you have a php file but you call it index.html it just serves it without processing it because the server doesn’t know to process it as a php file. Same thing with SSI. It doesn’t know to use includes because you didn’t use the proper file extension. It’s just serving it as is.
I have no idea What I meant. I think it was a confusing way to ask the second question I asked you (confirmation on which file will have the .shtml extension).
Haha. I know that feeling. I found abbreviations and emoticons for things/words ive never heard of. Idk, btw,and ttyl are enough for me.
wait, wouldn’t that prevent the server from processing PHP in .php files? Or should the line be:
Ah. The calling file should have the special file extension. The include file can be anything, even .txt or .inc or .blah, as long as it matches the file in the include statement.
Apologies, I had a busy weekend and I guess I went a little too off topic. Speaking on which, thank you @TechnoBear for teaching me how to highlight off-topic (parts of) posts.
Back on topic, i tried changing index.html to index.shtml and opened it again in chrome and the background was not red. So that means that the include did not work properly, right?
Here are new links to the files as I changed the extension of index.html to index.shtml (so the old links won’t work):
1.) index.shtml
2.) include.html
Sorry for keeping you, @imaginekitty waiting much longer than it should have been .
it doesn’t work. Dropbox doesn’t support PHP. But if it works now on your sever then I trust that it will work on my actual server.
Once i make the changes and upload the site, if i have questions, do you mind if i PM you?
Also if and when @ralph_m is online can he or anyone else answer my question on the line to add to the .htacess file to get php parsed in .html files?
Here it is again:
wait, wouldn’t that prevent the server from processing PHP in .php files? Or should the line be:
well i just wanted to know how to do the .htacess change properly for learning sake.
But why wouldn’t i? I know that you be a dangerous questions to ask, but it seems like an okay solution.
i think a bad thing about it is that i have to change the .htacess file.
Meaning, my HTML document will be parsed as html, as html in a php document outside of the <?php ?> tags is, and the includes will be parsed as PHP— i don’t see any issues with that.
I probably shouldn’t make comments on stuff I don’t understand well enough. That line used to work for me when I had PHP on a .html page (for testing only, as I don’t do it in real life) but on my new server it doesn’t work, so so much for that. I gather different servers require different .htaccess code, but none of the ones I’ve seen work on my new server (I’ve just tested them). So now I can’t test whether not having the .php in the htaccess rule stops PHP working on .php pages or not. Sorry!