calling cgi changes default directory

When I call cgi from my html, which takes this same html and outputs it to screen, I can't see images.
Is there any other way to fix the problem than write exact paths
before each image?
I think calling cgi changes default directory to cgi-bin, can I somehow stop that?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do you use SSI to call CGI ?
Why do you need this scheme ?

Indeed, the current working directory shouldn't affect images et all - but the current path for browser should.

If you have you HTML file as
images in:
and cgi-script:

then u can use path to images as
and this should work for HTML and for CGI.
kakoAuthor Commented:
I cant use path SRC="../images/file.gif"

cause: I have files in the directories:




Is it difficult for you to move file.html to subdirectory ?
This whould solve the problem the simpliest way. Otherwise you'll have to do magic things - replace IMG SRC=a.gif with
IMG SRC="../a.gif"
Whenever I run a .CGI program, I always make sure I have changed to the proper directory.  I always write my .CGIs in C.  However, this should be translatable into whatever language you are using.  It works by pulling the command line (i.e. c:\inetpub\wwwroot\test.cgi) and then cutting it off at the last backslash (i.e. c:\inetpub\wwwroot\), then switching to that directory.

void main(int argc,char *argv[])
  char *ptr;
  char temp[100];

  //pull the correct directory from argv[0]
  if(argc) {
    if(ptr=strrchr(temp,'\\')) {
Try this code to replace path to images:

$str_from_html_file = <FH_HTML>;
$str_from_html_file =~ s#SRC\s*=\s*"*([^"\s]+)"*#SRC="../$1"#gi ;

print $str_from_html_file;

Is it suitable answer to your problem ?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.