Link to home
Start Free TrialLog in
Avatar of rukiman
rukiman

asked on

search engine friendly script problem

I have written a search engine script using PHP ie accessing http://www.test.com/catalogue/chairs/a.html

calls a PHP script called "catalogue" that passes in the values "chairs" and "a.html". My script then goes into the directory "chairs/a.html" and spits out the information after inserting them into a template html page to make it fit the theme of my website. The problem is that paths all seem to be wrong and all the images and CSS style sheet links are invalid. If I just for debugging sake hardcoded "chairs" and "a.html" as parameters within the script then just called

http://www.test.com/catalogue

everything is displayed correctly! so the "/chairs/a.html" appended after the url is causing the invalid paths. How can I fix this? I don't really want to make use of absolute paths in my theme page.
Avatar of rukiman
rukiman

ASKER

I might also add that the a1.html has content that links to images and these are relative to the chairs directory while the template that the catalogue script is using is relative to the home directory.
You should show us a bit of your code.

Don't forget that if you include some files in php, the path is relative to the main file...

For example:
your directory:

index.php
catalogue/chair.html
images/chair.png

index.php includes
catalogue/chair.html

and in chair.html you want to display:
images/chair.png

you'll have to use: <img src="images/chair.png" width=... /> and not <img src="../images/chair.png" width=... />

if that's not the point, post some code... we'll see !
ASKER CERTIFIED SOLUTION
Avatar of shmert
shmert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rukiman

ASKER

ok I dont have the code with me on this computer but hope this helps

a1.html has the following content

this is a test <img src="cat.jpg"></img> woo hoo
--------------------------------------------

the catalogue PHP script is as follows

<?php

// get the directory and filename from the url as we are using GET
// $dir is the first input, $page is the second input

$basedir = "htmlcatalogue/";

$file = file( $basedir . $dir . "/" . $page);

?>

<html>
<body>
ok lets see what we pulled out: <br>
<? php echo $file ?>

<img src="dog.jpg"></img>
</body>
</html>


-----------------------------------

and here is the directory structure

htmlcatalogue ------------------->adapt-------->a1.html
                                                                    cat.jpg
catalogue (php script)
dog.jpg

------------------------------------

the script is invoked as follows:

http://www.test.com/catalogue/adapt/a1.html

----------------------------------------
Do this:  right-click on the broken 'cat' image and open it in a new window in your browser.  Look for error messages.  Also, look at the URL.  The URL for the cat image is calling the catalogue php script.  Simplest fix is to keep any images/external stylesheets/javascript stuff in a separate directory, and reference it using the complete URL.

<img src="http://www.test.com/images/cat.jpg" />