Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Including an HTML file in another HTML file

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?

Avatar of jessegivy
jessegivy
Flag of United States of America image

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
Avatar of Richard Korts

ASKER

To jessegivy:

I tried that. Same result (nothing).
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
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
To b0lsc0tt:

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

ASKER CERTIFIED SOLUTION
Avatar of b0lsc0tt
b0lsc0tt
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of doraemon-nolife
doraemon-nolife

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
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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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?
> 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.
>> 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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Forced accept.

Computer101
EE Admin