?
Solved

Including an HTML file in another HTML file

Posted on 2007-07-19
17
Medium Priority
?
224 Views
Last Modified: 2013-11-18
I want to include some standard menu navigatiion html in a lot of files on the web site.

I've done this before is asp & it worked.

Now I'm trying  <!--#include file = "menu.inc" -->. It doesn't work.

I earlier tried menu.html, didn't work either.

Web server is Apache. There is a .htaccess file in the root (not in the directory I'm working in) that has this content:
Options -Indexes
Options +Includes

What's wrong?

0
Comment
Question by:Richard Korts
  • 5
  • 3
  • 2
  • +5
15 Comments
 
LVL 12

Expert Comment

by:jessegivy
ID: 19527917
Have you tried something like this:

<!--#include virtual="http://yoursite.com/directory/menu.html" -->

virtual allows for using path information in the include.  

Good Luck,

Jesse
0
 

Author Comment

by:Richard Korts
ID: 19527975
To jessegivy:

I tried that. Same result (nothing).
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19528054
You need to tell Apache what file type is used.  I am not an Apache expert but you need lines like ...

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

Your html file that has the include line needs to end with the extension you specify (i.e. shtml).

Depending on the rest of your setup you may need more.  Take a look at http://httpd.apache.org/docs/1.3/howto/ssi.html for some extra info.

Let me know if you have a question or need more info.

bol
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19528062
If you have an Apache server do you have any support for server languages installed or enabled?  If so those are often the best way to include files.  PHP would be a common one for an Apache server.

If you can use PHP then let me know and I'll tell you how to do an include.

bol
0
 

Author Comment

by:Richard Korts
ID: 19528202
To b0lsc0tt:

I can use php. Do I have to change ALL the html files to php?

0
 
LVL 54

Accepted Solution

by:
b0lsc0tt earned 672 total points
ID: 19528268
Not all of them, only those that need an include.  Of course maybe that will be all of them.

You basically need to just change the file extension (e.g. filename.php).  A PHP include is done with a line like ...

<?php
include 'menu.inc';
?>

You can find more info on that function at http://us2.php.net/include/.  There are some similar functions like require(), include_once(), etc that you may need to use in some situations.

Let me know if you need anymore info or have other questions on this.

bol
0
 
LVL 4

Expert Comment

by:doraemon-nolife
ID: 19529571
It is highly possible that your web server is not configured to enable SSI

Please refer this site for the details of how to enable SSI in your web server:
http://bignosebird.com/sdocs/enable.shtml
0
 
LVL 1

Expert Comment

by:Martin Cotterill
ID: 19536452
It can be done, but as b0lsc0tt says, the file that has the include inside it must end with the extension .shtml.

If the file is in the same directory, you would use <!--#include file="menu.html" --> and if its held in a different directory, use <!--#include virtual="/directoryName/menu.html" -->.

Have a look at http://www.htmlgoodies.com/beyond/webmaster/article.php/3473341. This is a pretty good tute on SSIs.

Regards
0
 
LVL 27

Assisted Solution

by:Nopius
Nopius earned 664 total points
ID: 19538265
rkorts, hi.
Forget about .php suggestions, but b0lsc0tt was almost right about AddHandler.


1) Check your global httpd.conf (not .htaccess) file, does it have Options +Includes or AllowOverride All or AllowOverride Includes

2) If you have no Options +Indexes in _global_ config or have no AllowOverride All, just add and restart apache.

3) I guess that you have 'AllowOverride All' in httpd.conf, so everything else can be done via .htaccess:

AddHandler server-parsed .html
Options +Includes


If you have no 'AllowOverride All' (and don't like it) in global httpd.conf, you should add 'AddHandler server-parsed .html' also to global condig and restart apache.

0
 

Author Comment

by:Richard Korts
ID: 19540040
To all,

It seems clear that either way I have to change all html files effected (about 200) to either shtml or php.

Including ALL links to every such file.

Basically I have to do a global replace of html with php or shtml. But it's of course not that simple because there are external reference links, etc. that CANNOT be changed.

The whole purpose behind this is to avoid manual edits of 200 file every time the pull down menus change. So I guess I do it one last time, then change the include file henceforth.

So it's manually editing the 200 files.

Right?
0
 
LVL 27

Expert Comment

by:Nopius
ID: 19541212
> It seems clear that either way I have to change all html files effected (about 200) to either shtml or php.

It doesn't really matter what extension have your files. It may be .shtml or .html. It does matter what handler is processing that extension.

> Including ALL links to every such file.
> Basically I have to do a global replace of html with php or shtml. But it's of course not that simple because there are external reference links, etc. that CANNOT be changed.

That's why I recommended to add SSI handler to .html without renaming, so you don't need to fix any links.


> So it's manually editing the 200 files.
> Right?

No. The only reason for file editing may be adding "include" tag for common menu, but not changing links to your html files.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 19541505
>> It seems clear that either way I have to change all html files effected (about 200) to either shtml or php. <<

You don't have to actually change the extension but that is the minor part.  As Nopius pointed out the SSI extension can be set and so can the one the PHP engine uses.  In other words you can keep the file extension as html if you want.  You have to change the files to add the include anyways so it is better to stick with the default.  If you tell either SSI or PHP to look at html then ALL html files will be processed and that can inefficient.

>>  The whole purpose behind this is to avoid manual edits of 200 file every time the pull down menus change. So I guess I do it one last time, then change the include file henceforth. <<

I disagree about forgetting PHP altogether.  If all you want is the include then setting up SSI might be easier.  However if you really want to avoid manual edits and improve your pages you will eventually need server script.  SSI won't offer that so you would have to rework the pages again.  If you start to use PHP then you can add server script at any time to allow you to make dynamic pages, use databases, check forms, send emails and all of the other things PHP and other server language will support that SSI doesn't.

I am not saying SSI is bad; it isn't.  If you go for SSI it looks like Nopius provided some more info that hopefully will be all you need, with the other comments maybe, to setup SSI.  I just wanted to let you know there can be advantages to PHP. :)

Let me know if you have a question about anything I said.

bol
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 664 total points
ID: 19603019
# your httpd.conf should look like:

        Options Includes
        AddType text/html .shtml
        AddHandler server-parsed .shtml

these settings must apply to the directory where you have the files (menu.html, menu.inc), means the corresponding <Directory ...> and <Location ...> directives
You also can use .html like:

        AddHandler server-parsed .html

but that's a perdormance bottleneck.

Then you include should look like:

   <!--#include file = "menu.inc" -->

if this include is in your index.html file, the menu.inc file must reside in the same directory.
If it is not working, please check xour apache's error_log and post relevant messages.
0
 
LVL 54

Expert Comment

by:b0lsc0tt
ID: 20008162
mplungjan,

Thanks for your time cleaning.  I recommend a split as follows:

Accept: b0lsc0tt {http:#19528268} & Nopius {http:#19538265} & ahoffmann {http:#19603019}

Let me know if there are any questions about this (I can explain it if needed).  I hope it helps.

bol
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20166816
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question