Solved

search engine friendly script problem

Posted on 2003-10-27
5
276 Views
Last Modified: 2008-03-17
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.
0
Comment
Question by:rukiman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:rukiman
ID: 9626732
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.
0
 
LVL 2

Expert Comment

by:errows
ID: 9626940
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 !
0
 
LVL 11

Accepted Solution

by:
shmert earned 125 total points
ID: 9627805
The problem is, your browser sees the URL "http://www.test.com/catalogue/chairs/a.html" and doesn't know that catalogue is actually the php page.  When the a.html page references an image or a stylesheet with a relative URL, the browser will send a request to, for example:  http://www.test.com/catalogue/chairs/image.jpg.

I haven't seen your code for the catalogue script, but I bet it sees this request and tries to treat the image.jpg file as a template, just like the a.html page.

Your best solution would be to either
* Use absolute locations to all your images & css files, which are served directly via the webserver without going through the catalogue php script
* Make the catalogue script smarter to not treat non-html files as templates
* Use <base href="http://www.test.com/static_files"> to set the base URL for all relative links in a page.
0
 

Author Comment

by:rukiman
ID: 9630886
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

----------------------------------------
0
 
LVL 11

Expert Comment

by:shmert
ID: 9635074
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" />
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question