2

I use MAMP to develop sites. I have each site in it's own folder in the htdocs folder. I manage one site that I need to use ssi directives on, because the host doesn't allow php includes.

I've un-commented these lines in httpd.conf file:

AddType text/html .shtml
AddOutputFilter INCLUDES .shtml

I added a .htaccess file in the htdocs folder with the following:

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

On the site index page the include works using:

<!--#include file="top-nav.shtml" -->

But it does not work on files in any sub folder. I get this error:

[an error occurred while processing this directive]

Jamie
  • 123
  • 1
  • 4
  • 1
    I thought `WAMP` was *Windows* (+apache, MySQL, PHP) and `MAMP` was MacOSX, etc. Not that it likely matters for your question. – Andrew Barber Dec 19 '10 at 01:12
  • The though by including both is that they are mostly the same environment, so I didn't want to exclude possible answers. Let me know if you think I should edit the post. – Jamie Dec 19 '10 at 01:28
  • 1
    Your setup can't be both. If it matters, you should give the correct information. If it does not matter, you should not give any. So which is it; Windows or Mac? If it's Windows, don't say "It's MAMP", because it's not. – Andrew Barber Dec 19 '10 at 01:32

2 Answers2

1

Are you using the exact same include directive on all the sub-folder pages, too? If so, your problem seems clear: You aren't linking to the include file properly (unless you have that same file in every single directory on the site, which would sort of defeat the purpose)

Other than that, I'd want to know; what is the error you are getting on the server? Why do you think that SSI is not 'enabled' - especially considering it is working on one file, at least.

Andrew Barber
  • 1,089
  • 12
  • 23
  • @Andrew I'm using: in the sub folders. I think it's not working because the file only gets included on the index page and not on the index page one level deep. Not sure what error I am getting. Other than the one that prints out on the page"an error occurred while processing this directive". Which I think is a sign that ssi is "working" but... – Jamie Dec 19 '10 at 01:26
  • @Jamie - Your include path above appears to include a period `.` at the beginning. Does that not denote the current path in includes, just as it does in the file system itself? – Andrew Barber Dec 19 '10 at 01:30
  • @Jamie - Also... you really should get access to the actual error messages. debugging without them is going to lead you to an early grave. – Andrew Barber Dec 19 '10 at 01:31
  • @Andrew Forgive me for not completely understanding your question, but I have the period in there to denote a relative path to the file I am trying to include. – Jamie Dec 19 '10 at 01:35
  • @Jamie - The end result is exactly the same as just "top-nav.html"... it's looking in the same directory as the file is. Perhaps you meant to use double dots instead? "../top-nav.html" – Andrew Barber Dec 19 '10 at 01:41
  • Ahh yes, that is true. I changed it, but it still produced the same error. It seems really strange that the .htaccess file is in htdocs and the file that it works on is in htdocs/site/index.html, but it doesn't work on a file in htdocs/site/sub-dir/index.html. It's very frustrating. Is there anything else that you can think of? Thanks for your help. – Jamie Dec 19 '10 at 01:52
  • You really need to see the actual error message. Otherwise, we're just making blind guesses in the dark. – Andrew Barber Dec 19 '10 at 01:54
  • Found the error: `[Sat Dec 18 21:08:43 2010] [error] [client ::1] unable to include file "../top-nav.html" in parsed file /Applications/MAMP/htdocs/rikshaw/udaipur/index.html, referer: http://localhost:8888/rikshaw/` – Jamie Dec 19 '10 at 02:16
  • Try it with `virtual` instead of `file`; first as it is now (starting with the double-dots) and then with a rooted virtual path instead (so, "/top-nav.html" if the file is in the web root) – Andrew Barber Dec 19 '10 at 02:20
  • It works as `virtual` with the relative path locally. But... the host, Yahoo shopping cart doesn't allow the `virtual` directive. I am going to test again to be certain. But if not is there a way to get it to work as `file` that you know of? – Jamie Dec 19 '10 at 02:27
  • I think that with `file`, the only way to make it work anywhere but the current directory is to specify the *full, local path* of the file... but I've not used SSI in so long, I'm not 100%. Try it with the full local path starting at root. The error message would usually have expanded the path for you if it can do relative paths, I *think* ... – Andrew Barber Dec 19 '10 at 02:36
  • Ok, it works using `virtual` instead of `file` on the live environment too. I am grateful for your effort on this, Andrew. +1 for answer and +1 for staying power. Thanks! – Jamie Dec 19 '10 at 02:38
0

Not sure if this was resolved because the question is still open.

To add some clarification. use "file" when the file you're including resides in the same directory as the file that is referencing it. Use "virtual" when the file resides in a sub-directory.

Also, just my opinion, but it's good practice to put your includes in a directory of their own (usually named "inc" or "includes").

So for what you're trying to accomplish, you'd want to use...

<!--#include virtual="../inc/top-nav.html" -->
slm
  • 7,355
  • 16
  • 54
  • 72
CCCCC
  • 1
  • 1