Welcome to WebmasterWorld Guest from 54.196.244.186

Forum Moderators: incrediBILL

Message Too Old, No Replies

Can't get html includes to work.

     
3:22 am on Apr 9, 2007 (gmt 0)

Full Member

10+ Year Member

joined:May 2, 2004
posts:211
votes: 0


I'm pretty lousy at HMTL, but I'm leaving the world of frontpage (where I've used frontpage includes) and I am trying to get some HMTL includes to work "on their own".

I've created a file called testing.html, and where I want the included content I am putting:

<!--#include file="included.html" -->

I am putting my included.html file in the root, but nothing is appearing when I pull up the testing.html page.

are there any common mistakes / anything i might be missing?

Thanks in advance..

gmac

5:06 am on Apr 9, 2007 (gmt 0)

New User

5+ Year Member

joined:Feb 20, 2006
posts:31
votes: 0


Change your test.html to test.asp and then try it.
2:42 pm on Apr 9, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:May 7, 2003
posts:472
votes: 0


Try:

<!--#INCLUDE VIRTUAL="included.html"-->

3:49 pm on Apr 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2002
posts:3171
votes: 8


ok firstly are you testing the webpages using a webserver or are you just opening them in your browser on your local machine?
[of course the webserver can be on your local machine too]

if you are using a webserver is it IIS (eg. is it microsoft)

if the above two are correct then you can use either

<!--#include file="included.html" -->
in this case the file path must be relative, in other words in this case the file testing.html must also be in the site root.

or
<!--#include virtual="/included.html" -->
where the file testing.html can be anywhere under the root

however you are most likely to have to change the file name as well to:
testing.asp

4:08 pm on Apr 9, 2007 (gmt 0)

Full Member

10+ Year Member

joined:May 2, 2004
posts: 211
votes: 0


I am testing this live online, not on my local machine.

I'll check on the server, though e3servers (where I host) says it can handle includes no problem. Apache is installed.

What does changing the extension to .asp do for me? I'm apprehensive about this for search engine reasons - don't want to change my url's on a 5 year old site....

4:13 pm on Apr 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member penders is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:July 3, 2006
posts:3123
votes: 0


however you are most likely to have to change the file name as well to:
testing.asp

Or change to:

testing.shtml

This is to get the web server to parse your file for server-side includes (SSI's) (ie. <!--#include...). By default, .html files are not.

[edit]

I believe .shtml is the default file extension if you are wanting to use SSI's. Changing to .asp (Active Server Pages) will also work because ASP supports these includes also (*I think that's right?*) - HOWEVER, if you are on Apache, your server may not support ASP!

5:46 pm on Apr 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2002
posts:3171
votes: 8


ok if you are on apache you do it differently.

first ensure that the server is set to parse .html files with the php engine
[if it isn't you can create an .htaccess file to do this easily, so there is no need to change your file names, but most hosts have a control panel where you can set something like this - if not i'll post the .htaccess code you need to use here]

then to include files using php you do this:

<?php
include "/var/www/html/mywebsitefolder/myincludefile.htm";
?>

in this case you use the filepath of the file on the server, not from your root, your host should tell you the path to your root, in the above example i have guessed that your 'root' folder is infact here

/var/www/html/mywebsitefolder/

which is only possibly where it is, most hosts will use a similiar file structure but probably not exactly that.

[sorry for the red herring re .asp, i just assumed you were on a windows server because you had used front page extensions previously, which may not have been the case]

6:06 pm on Apr 9, 2007 (gmt 0)

Senior Member from GB 

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 10, 2002
posts:927
votes: 0


I'm on Apache and use this to include stuff:
<?php require "includedfile.inc";?> using the filepath from the host page to the included file.
My server is set to parse html and htm for php as topr8 describes.
I shouldn't worry about changing names of included files, since they are seen as part of the main page, not in their own right.
7:30 pm on Apr 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


penders' post is probably the most likely solution **IF** this is a linux server. .ASP, php and other languages all have valid include functions but only server-side includes (SSI) are specific to file inclusion in a page.

To which I would only add,

<!--#include file="included.html" -->
Use include file if the included file is in the same directory as the .shtml.

<!--#include virtual="/some/pathto/included.html" -->
Use include virtual if the included file is in a different directory than the .shtml.

7:41 pm on Apr 9, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member topr8 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 19, 2002
posts:3171
votes: 8


this is a linux server and penders solution is likely the easiest except the op said:

>> don't want to change my url's

in which case he will either have to use the php include method or use the host control panel to set up .html files to allow includes

10:24 pm on Apr 9, 2007 (gmt 0)

Full Member

10+ Year Member

joined:May 2, 2004
posts:211
votes: 0


it is apache on linux.

Topr8 - I can use php include commands and my pages can still end in .html (so as not to screw up my url's)?

thanks

6:58 am on Apr 10, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


To parse ordinary HTML for includes, no alternate language is required, no fiddling with extensions, and your URL's can remain the same. Locate the file httpd.conf on your server. Within that file you should find the addType directive for SSI's:

AddType text/x-server-parsed-html .shtml

You can alter this line to parse all html

AddType text/x-server-parsed-html .shtml .html .htm

or simply add another line

AddType text/x-server-parsed-html .html

then restart httpd

/etc/rc.d/init.d/httpd restart

And you're good to go.

[hoohoo.ncsa.uiuc.edu...]

3:56 am on Apr 11, 2007 (gmt 0)

Full Member

10+ Year Member

joined:May 2, 2004
posts:211
votes: 0


It works now, thanks for all the help!
7:17 pm on Apr 29, 2007 (gmt 0)

New User

5+ Year Member

joined:June 28, 2006
posts:10
votes: 0


Due to the overhead for the server to evaluate every .html file for the potential SSI's, setting all .html is generally to be avoided.

I believe the preferred method is to set:

XBitHack on

Then simply chmod +x blahblah.html so that the file has the executable bit set on. Then, the server will evaluate only those files with the +x flag, in searching for SSI's (in addition to its normal .shtml behaviour of course).

9:16 pm on Apr 29, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


That's an interesting opposition, one I used to adhere to, but every administrator I talk to says it's no longer an issue unless you're using a **really** old machine for a server. Anyone else out there think it's still "selfish" to parse all files?

selfish=as one administrator described it once, long ago

11:08 am on May 5, 2007 (gmt 0)

New User

5+ Year Member

joined:Mar 25, 2007
posts:8
votes: 0


Change your test.html to test.asp or test.shtml and then try it.