homepage Welcome to WebmasterWorld Guest from 50.19.199.154
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Include .HTM File not working - how to avoid changing the extension?
Mdmzd




msg:4571745
 6:00 am on May 8, 2013 (gmt 0)

My include file is not working. My files end with .htm and I believe that there is a workaround to make include files work without changing the extension to .php or .shtml or any other.

I have a file called leftnav.html which I want included in another file called test.html. I have a folder called Includes and have uploaded the leftnav.html file both inside the folder as well as outside to see which one takes.

The leftnav.html file has :

<div align='center'>
<ul>
<li>Home</li>
<li> Contact Us</li>
<li>Faq</li>
</ul>
</div>

And the test file has:

<HTML>
<TITLE>Test File</TITLE>
<body>
TEST
<p>

<!--#include file="includes/leftnav.html" -->
<!--#include virtual="includes/leftnav.html" -->
<!--#include file="leftnav.html" -->

</body>
</HTML>

My .htaccess contains the following:

# -FrontPage-
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName gynaeonline.com
AuthUserFile /home2/mdmzd12/public_html/_vti_pvt/service.pwd
AuthGroupFile /home2/mdmzd12/public_html/_vti_pvt/service.grp
AddType text/x-server-parsed-html .shtml
AddType text/x-server-parsed-html .html .htm

I believe that the last two lines should make the server show up the includes.

My webhost says that the server is parsed for Includes.

I can't make out what I am doing wrong.

Please help.

 

lucy24




msg:4571766
 8:26 am on May 8, 2013 (gmt 0)

You're missing:

AddOutputFilter INCLUDES .html .php

(substitute the extensions you actually use)
That's assuming you'll be adding include files to everything. Option B is the x-bit hack which involves setting permissions in individual documents. It isn't very complicated in other words, I've done it myself but requires a little more work than the global version.

<!--#include file="includes/leftnav.html" -->
<!--#include virtual="includes/leftnav.html" -->


Either
#include file="local-relative-path"
or
#include virtual="absolute-path-beginning-in-slash"

Mdmzd




msg:4571930
 5:15 pm on May 8, 2013 (gmt 0)

Lucy,

Thank you for your reply.

I have added the code you suggested but it is still not working.

My .htaccess now contains:

# -FrontPage-
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName gynaeonline.com
AuthUserFile /home2/mdmzd12/public_html/_vti_pvt/service.pwd
AuthGroupFile /home2/mdmzd12/public_html/_vti_pvt/service.grp
AddOutputFilter INCLUDES .html .php .htm
AddType text/x-server-parsed-html .shtml
AddType text/x-server-parsed-html .html .htm

And the test file contains:

<HTML>
<TITLE>Test File</TITLE>
<body>
TEST
<p>


<!--#include file="leftnav.html" -->
<!--#include file="includes/leftnav.html" -->
<!--#include virtual="/includes/leftnav.html" -->

</body>
</HTML>

Should I put in the entire url starting with the domain with #include virtual (http://www.mysite.com/leftnav.html) starting with a slash?

What is a x-bit hack? What is the code? Does it need to be put in in every page of the site or only in the .htaccess?

Thank you for your help.

Regards.

lucy24




msg:4571996
 7:14 pm on May 8, 2013 (gmt 0)

What do you see in your pages at this point? Since you haven't set a custom include error message, you should see something like "include error" right in the body of the page for all to see. If you don't see the error, the file isn't even trying to do the includes. In that case you'll see the raw "<!--include et cetera" code when you look at the page source code.

:: wait ::
:: stop ::
:: rewind ::

Sorry. It's so obvious I overlooked it. In addition to AddOutputFilter you need
Options +Includes

or, for most sites,
Options -Indexes +Includes

--which reminds me that unless you have the worst host in the world, you should not need
IndexIgnore .htaccess
because a normal config file will already have rules about files with leading dot.

<!--#include file="includes/leftnav.html" -->
<!--#include virtual="/includes/leftnav.html" -->

It's a good thing your includes aren't working, or this would result in the same file being included twice. That's assuming the "includes" directory is in the same place as the file doing the including. (I checked in MAMP. I thought it would make an error but it simply included the same thing two times in a row.)

The Options +Includes line is unnecessary if the config file has includes enabled globally by default-- but this is very unlikely, since most people don't use them and it makes extra work for the server.

Edit:
I had to go look up X-Bit Hack because I no longer use it. The htaccess/config directive is
XBitHack on
By itself, this does nothing. In the specific files that will be using includes, you need to set permissions to owner:execute. Exact mechanism depends on how you're accessing your files. In Fetch there's an Info window with a bunch of checkboxes. If you're doing it locally there's
:: ugh, ugh, shudder ::
a command-line equivalent. My notes say "chmod +x {drag file}". That's in
:: ugh, ugh, shudder ::
Terminal.

But if you plan on using includes everywhere in all directories, you don't need this. It's appropriate for situations where only a few files in a larger directory will have includes.

Mdmzd




msg:4572236
 9:08 am on May 9, 2013 (gmt 0)

Lucy,

I am sorry to bug you like this but it is still not working.

When i open the page at www.mysite.com/test.html, i see only a white page with test written on it. There is no error code. Viewing the page source, it contains:

<HTML>
<TITLE>Test File</TITLE>
<body>
TEST
<p>


<!--#include file="leftnav.html" -->
<!--#include file="includes/leftnav.htm" -->

<!--#include file="leftnav.html" -->
<!--#include virtual="includes/leftnav.htm" -->

</body>
</HTML>

Nothing else shows up.

I have added the code you suggested. I have been struggling with this all this time and also added a number of other codes I found on the internet, hoping something will work - nothing has so far. I also removed the following from the .htaccess:

# -FrontPage-
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName gynaeonline.com
AuthUserFile /home2/mdmzd12/public_html/_vti_pvt/service.pwd
AuthGroupFile /home2/mdmzd12/public_html/_vti_pvt/service.grp

My .htaccess now reads:

Options -Indexes +Includes
AddOutputFilter INCLUDES .html .php .htm
AddHandler application/x-httpd-php .html .htm
AddType text/x-server-parsed-html .shtml
AddType text/x-server-parsed-html .html .htm
AddType php .html .htm
AddHandler x-httpd-php .html .htm
<FilesMatch ".*\.(htm|html|php)$">
SetHandler application/x-httpd-php5
</FilesMatch>

Please help - I really do not know what I am doing wrong. Thank you so much for all your suggestions so far.

With regards,

lucy24




msg:4572259
 10:11 am on May 9, 2013 (gmt 0)

Backtrack. Try commenting out everything except the lines

Options...

and

AddOutputFilter...

In particular, I am leery of that huge wad of Type and Handler lines. (I added an AddType line when I started using includes, but I later learned it isn't necessary. Doesn't do any harm, though.) I suspect they're colliding with each other, especially with that FilesMatch envelope that seems to say the opposite of what everything outside the envelope is saying.

Are you doing this on your live site? I strongly recommend getting a pseudo-server like MAMP or WAMP. You will sometimes come to grief if the pseudo-server uses a different php than your live server, but for straight html it should make no difference. And it will save you a lot of time being able to test everything on the fly.

:: wandering off in search of a moderator because this question will have better luck in the Apache forum ::

There's an oldish thread in Apache about SSIs. Apparently there's a certain amount of black magic involved-- the kind where it only works on alternate Tuesdays when you stand on one leg and turn around three times and speak to the server in a particular dialect of Quechua. But once it starts working it will continue to work.

Mdmzd




msg:4572712
 2:28 pm on May 10, 2013 (gmt 0)

Lucy,

I carried out your suggesiton but it still does not work.

What I don't understand is why the test file shows a blank page. If there was an error, it should have showed an error code, right? or it should have shown the HTML ( <!--#include file="leftnav.html" --> ) etc.

But the page is just blank.

Also I read that a test file showing the following code should show the time:

<HTML>
<TITLE>Test File</TITLE>

<!--#config timefmt="%A" --> <!--#echo var="DATE_LOCAL" -->

</HTML>

But this page comes up blank too.

I really don't lknow what to do at this time.

Thanks for your help so far.

lucy24




msg:4572828
 7:10 pm on May 10, 2013 (gmt 0)

The error message only shows up if the server tries and fails to execute the Include. If the page source still shows the
<!-- include
line, it means the server isn't trying. Uhm. That sounds as if I'm faulting the server. It's just a dumb machine that does what it's told. ;)

This line will be in the page's source code-- View Source or similar in your browser-- NOT in the visible page. (Notice how the format uses "comment" tags.) The default Include error message is visible text; that's one reason you want to change it.

This question has now been bumped over to the Apache forum, so it should pick up an answer from ::cough-cough:: someone more helpful. There's a particular thread that lists all the possible permutations that some server somewhere might conceivably demand before it is willing to do SSIs, but I can't find it. I did come across this one

AddHandler server-parsed .html

which you could always throw into the mix. I've never needed it myself, but it was in a thread from 2010 so it probably won't make your server explode.

Incidentally, you keep saying "blank page". Never mind what you see in the browser. What's important is what you see in the source code (as displayed by your browser). There's a big difference between source code that's truly empty, and source code that contains a bunch of js or php, none of it resulting in visible content. Always look at the source code, because that's what the server sends out.

Philosophical observation: SSIs are extremely useful if you're coming from a background of raw, hand-rolled HTML as I did. They help you get used to the idea that what you see in your code will be different from what the end user sees if they View Source. This is a big conceptual step. If you're coming from a CMS background, you're going in the opposite direction.

Mdmzd




msg:4575149
 3:19 am on May 18, 2013 (gmt 0)

Lucy,

Just an Update:

I contacted my webhost again and after a large number of back and forth replies, I get this:

"Hello,
thank you very much for sharing your experience with us. I'm contacting you regarding the survey you have filled out about our services. I've checked your website and found the issue causing it. On this server, there is nginx server running as a frontend of apache webserver. Because nginx was configured to handle all static content ( including .html and .htm code ), the includes weren't processed properly. I've configured nginx to not process the .htm and .html files but forward them to apache server and now the includes are working as you can see."

My Includes are working now.

Thank you for your help so far - you have been more responsive and more helpful than my webhost.

With regards.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved