Welcome to WebmasterWorld Guest from 50.17.117.221

Forum Moderators: phranque

Message Too Old, No Replies

Path problem with "clean" urls

     
3:45 am on Sep 22, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts: 88
votes: 0


Hi, I hope someone can provide some help on this issue which surely has a very dumb solution, yet I can't seem to find it.

I'm passing a variable to a script in the 'fancy' format of "localhost/myscript/myvar" instead of "localhost/myscript.php?myvar", and this works quite well.

HOWEVER, this method creates a SERIOUS problem with relative paths:

When opening "localhost/myscript/myvar", a relative link that should point to "index.php" now points to "myscript/index.php", which does not exists. This is, ALL files linked from from myscript are now pointing to an invalid path, because "myscript" is taken as a subdirectory for all relative-path links.

This problem applies to ALL files with relative URL (css, js, etc), causing all of them to be not found when accesing the script.

There are millions of sites that pass variables this way; I checked out some sources, and files are also linked with relative paths... yet they magically point to the right path somehow.

I hope I explained myself correctly, because the problem is quite hard to specify and my native language is spanish. Any help is really appreciated.

PS. I can explain it completely again in different terms to try to make it clearer, but I can't link to any example because this forum does not allow any kind of links.

Regards,
Andrés

1:17 am on Sept 23, 2007 (gmt 0)

Senior Member from CA 

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

joined:Aug 31, 2003
posts:9063
votes: 2


The solution, as you probably suspected, is not to use relative URLs. ;) It is good practice to always stick to URLs which reference the root, such as
/path/to/stylesheet.css
.

Another option is to consider using a

BASE
URI defined in the document
head
section:

<base href="http://www.example.com/">
4:56 am on Sept 23, 2007 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 7, 2004
posts: 88
votes: 0


OK, but wait a second... isn't /path/to/stylesheet.css a relative link? On my extensionless PHP script that link would become myscript/path/to/stylesheet.css again....

I think the <base href="http://www.example.com/"> should do the trick, I just hope it's recognized by non-Microsoft browsers and mobile WAP browsers as well.