Jump to content

htm include file not working


socrates

Recommended Posts

Hello, I'm new and apologize if I have posted in the wrong place.

 

I have a site on which I use .php pages with php includes for the header and footer. I am redesigning a site for someone else and testing it on my own site. The site that I am redesigning uses the .htm extension for pages. So far I have been unable to include a header or footer on the .htm pages that I've uploaded to my site. The 'includes' fail to load. If I change the index page extension to index.php and use a php include then all goes well.

 

The footer.htm file is in the same directory as the index.htm file and I have been using <!--#include file="footer.htm"--> as the include code. I've tried changing the extensions to .html and .shtml, but to no avail.

 

Has anyone any idea why I can't get it to work? I'm probably making a basic error as I have limited knowledge of website design.

 

Thanks!

Link to comment
Share on other sites

The pages that hold the includes either need a .php extension to work,or you can add a line to your .htaccess file that tells the server to read .html as .php.

 

Thank you very much! Where do I find the .htaccess file and what line of code would I need to add?

Link to comment
Share on other sites

My advice if you do not know where to find the .htaccess file do not use that method. Try Andrea's way or just change the .htm or .html to .php also change the links from <href whatever .htm to .php I think this is what she was saying anyway, but I could be wrong.

Edited by grabenair
Link to comment
Share on other sites

Thank you for that. I can change all the page extensions to .php to TEST it on my site and it will work fine, but I need to find a way to include the header and footer as separate files in pages with the .htm extension. The site I am redesigning was built using .htm pages and I want to check that I can set everything up to work with that extension. I daren't change the page extension on the actual site being redesigned otherwise links into it from other sites will become defunct.

 

I hope that makes sense?

Link to comment
Share on other sites

The .htaccess file should be right in your root directory. Look at your server-side files. You usually have to open and edit it with Notepad, then save again as .htaccess.

 

Add this line:

 

AddType application/x-httpd-php .php .htm

 

if that does not work, search around your host site, I've found that sometimes, different servers have slightly different requirements.

 

Link to comment
Share on other sites

The .htaccess file should be right in your root directory. Look at your server-side files. You usually have to open and edit it with Notepad, then save again as .htaccess.

 

Add this line:

 

AddType application/x-httpd-php .php .htm

 

if that does not work, search around your host site, I've found that sometimes, different servers have slightly different requirements.

 

Okay. I've had a good look round the root directory and cannot see it, so I've submitted a ticket to the host to see if it can locate it for me. Once I find it I will add that line to it. I will do my best to report back on the result in case anyone else faces the same difficulty.

 

I sincerely thank you for helping and pointing me in the right direction.

Link to comment
Share on other sites

Okay. I've had a good look round the root directory and cannot see it, so I've submitted a ticket to the host to see if it can locate it for me. Once I find it I will add that line to it. I will do my best to report back on the result in case anyone else faces the same difficulty.

 

I sincerely thank you for helping and pointing me in the right direction.

 

Post Script: Andrea, you were spot on with that solution. The host has added .htm and .html to the .htaccess file and says that should fix the problem, although obviously didn't want to risk telling me where the file is. At this stage I will take her word for it as I'm too shattered to experiment any more tonight. Tomorrow is another day!

 

Once again thank you for all your help. I had spent hours trawling various sites trying to find the solution, so hopefully your posts will be of benefit to others.

Link to comment
Share on other sites

The host has added .htm and .html to the .htaccess file and says that should fix the problem, although obviously didn't want to risk telling me where the file is.

I guess that depends on your host - with every host I've ever worked with (ok - all THREE) the.htaccess file was right there for me to do with whatever I pleased.

Link to comment
Share on other sites

You can always create your own .htaccess file and supply the necessary logic to set the .htm or .html.

 

Typcially, (not always the case) you open up your text editor and apply the logic. Then save it as htaccess.txt . Notice it's a simple text file.

 

You would then upload that file to the root. Now to get it to work. You would need to login to your host's control panel and go to the file manager. Look for the htaccess.txt file. Just rename the file to .htaccess (no .txt extension but you now have a period in front of htaccess)

 

For me, it's even easier than that. I use Expression Web and it will allow me to edit the .htaccess file as is without having to download/upload and rename the file. This was I can update the file on the fly and see the changes instantly.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...