homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque & physics

Webmaster General Forum

Path problem with "clean" urls

 3:45 am on Sep 22, 2007 (gmt 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.




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

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

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 Sep 23, 2007 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved