Welcome to WebmasterWorld Guest from 54.158.143.40

Forum Moderators: phranque

Message Too Old, No Replies

How can I link to one SSI file from pages in separate directories?

SSI files stop working when I put pages in different directories

   
6:13 am on Feb 4, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I have a couple of SSI files in the root directory of my web site which I use for navigation bars. Everything works fine for the home page, but when I duplicate the page into a subdirectory and update the file path in the code, the SSI doesn't load.

This happens locally and also on the server.

For example for the home page the link to the SSI file is

navgation-left.ssi

and when I put the page into a subdirectory the link might be

../navgation-left.ssi

This all looks fine to me, but clearly I am missing something.

11:32 am on Feb 4, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Omit the double dots.

Double dots means "up one level".

Keeping track of that down multiple levels is a nightmare.

Use /nav-left.ssi with a leading slash so that you always "count from the root".

2:29 pm on Feb 4, 2009 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I agree, navigating from the root keeps things so much cleaner and easier to use, less confusing when you are trying to determine where your current filepath is too. If you are on Apache use virtual, not file -- virtual [httpd.apache.org] is much more useful.
12:50 am on Feb 5, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



With "counting from the root" the current location becomes irrelevant.
That's why I find it so useful.
5:43 am on Feb 5, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Sorry, but none of those solutions work. Perhaps I didn't explain this properly. I want to bring in the ssi file that is up one level.

I am only putting the html page down one level of directory. Surely the double dots points the link back at the root directory where the SSI file is?

I am not on Apache (Windows IIS), so the virtual option doesn't seem to work either.

So, if the html page and the ssi file are in the same root directory I have been using <!--#include file="nameofile.ssi" -->

Then I put another page one directory level down, but keep the ssi file in the root directory, shouldn't it become <!--#include file="../nameofile.ssi" -->

3:33 am on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Ah, ok. I realised that it was the images in the ssi file that were not showing up. I suppose I will have to use absolute links for them.
9:12 am on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Yes. Use the same "starts with slash" URL format for all links to CSS, JS, images, etc.
4:18 pm on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I have been using <!--#include file="nameofile.ssi" -->

See coopster's previous post - the "rule of thumb" with SSI is if it's in the same directory, use file, if it's in a different directory, use virtual..

<!--#include virtual="/nameofile.ssi" -->
<!--#include virtual="/dir/nameofile.ssi" -->

The "dot syntax" will always get you in trouble, or at least confused. Do the same within your SSI files:

/images/some-image.jpg

Never

../../some-image.jpg

(An ailment similar to Larry Wall's "toothpick syndrome")

Then I put another page one directory level down, but keep the ssi file in the root directory, shouldn't it become <!--#include file="../nameofile.ssi" -->

It could, but if you use the previous advice and do

/nameofile.ssi

you can move it anywhere.

Adapting this habit will allow you to move your files anywhere on your system and they will always connect, you won't even have to look. :-)

11:49 pm on Feb 6, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Thanks. But will that method work on a windows IIS server? I thought I require Apache?
8:26 am on Feb 7, 2009 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Ah. Thank you thank you everyone. It all falls into place at last. Just need to test everything on the server and I'm good to go.