Forum Moderators: phranque

Message Too Old, No Replies

path option

         

hugomsgomes

11:49 am on Feb 7, 2007 (gmt 0)

10+ Year Member



Hello people

I'm trying to know if there is a way for define a path in apache. For example:

I have a link with the href="img/logo.gif"

this link is a path for a folder img in the same directory of the html file, correct, but now i want to define a second path, if the first don't exist the server will look in the other path for the file "img/logo.gif".

Something like happens in the php
[pt.php.net...]
We could define the paths were he will look.

With the best regards
Hugo Gomes

jdMorgan

12:39 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can use mod_rewrite, specifically, the "file exists" check available with the "RewriteCond %{REQUEST_FILENAME} -f" directive. If the file exists, load it, otherwise, rewrite the request to the secondary URL-path.

Jim

hugomsgomes

12:07 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



OK i've explained wrong :)

For example in all files i have a logo at the top of the page and i want that all pages use the logo, the gif image is in a directory in the rootdoc (img/) and i want that all the files that have this image in their html code (because the html has only the relative path) use the img/ folder in where the .html file, but if doesn't exist a img directory ther the server will look at the rootdoc.

This happens because my site is built by lots of people some copy the img directory to their directory and ohter people don't copy the directory img. So the images are missing in same sub-sites. And i have lots of work inspecting all the directories and subdirectories of my site.

So the prioblem isn't with the link himself(because the link exists) the problem is with the path of the images contained in the html file.

And for this i didn't get any solution.

I hope i was clear :)

With the best regards

Hugo Gomes

[edited by: hugomsgomes at 12:11 pm (utc) on Feb. 8, 2007]

jdMorgan

10:51 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> OK i've explained wrong

Not really, but your concept of this as a 'Unix path' problem is misleading you.

I suggest taking the requested URL-path (converted and provided as a server filepath) in %{REQUEST_FILENAME} and checking to see if that exists. If so, do nothing, and allow that file to be served. If the requested URL does not resolve to an existing file, then rewrite the request to the root image URL-path.

This is done using mod_rewrite, using RewriteCond to check to see if %{REQUEST_FILENAME} exists, and if not, using a RewriteRule to change the URL-path so that it resolves to an existing 'common' image file. Two lines of code.

The result is the same, only the implementation differs from what you expected.

Jim