Click to See Complete Forum and Search --> : Relative URLs Not working


aprice42
12-15-2006, 03:52 PM
I am working on implementing relative urls on my website. For some reason they dont seem to be working as expected. For example:

I am referring to my style sheets as follows:

/css/base.css

the directory "css" is located in the root of my site "public_html".

Am I doing something wrong here?

Thanks,
Andy

KDLA
12-15-2006, 04:02 PM
If the page your working with is IN a folder, you have to back out of it, first, using ".." --
try "../css/base.css"
KDLA

factor
12-15-2006, 04:08 PM
Or you can set your base path with <base href="http://www.yourdomain.com/" /> (put in the <head>section of your pages) so all your relative urls will be relative to your base path. This way you can refer to your files from everywhere like css/base.css

aprice42
12-15-2006, 04:14 PM
In researching this matter online, before making my post, I came across this...
If a relative URL begins with the slash /, it is interpreted as relative to the server root. In our example, /foo.html would mean http://www.server.example/foo.html
Is this incorrect information?

KDLA
12-15-2006, 04:20 PM
Yes.
Reference: http://www.webreference.com/html/tutorial2/3.html

KDLA

aprice42
12-15-2006, 04:56 PM
thanks, I read through that, and will reread it too, for some reason I am having trouble grasping the syntax.

A relative URL that begins with / (a slash) always replaces the entire pathname of the base URL

so my understanding of this is that it says if you use a / in the URL it will be replaced with http://websitename.com/

Is that correct?

ray326
12-16-2006, 12:36 AM
Is this incorrect information?No, that is correct. A relative URL is one that has no protocol or hostname. If you begin it with "/" then it becomes a full path relative to the root of your site.

aprice42
12-17-2006, 12:05 AM
No, that is correct. A relative URL is one that has no protocol or hostname. If you begin it with "/" then it becomes a full path relative to the root of your site.

Thanks,

I got that to work... Now my challenge is dealing with using it in php includes. Is it possible to use the "/" technique in php code? for some reason it won't work for me...

ray326
12-17-2006, 12:37 AM
Some PHP functions may use explicit server paths (file system paths) instead of URLs. Those would break as "/" would be the root of the file system rather than the root of the web site.

factor
12-17-2006, 06:55 AM
You can put your base path into a variable and use it always when including files .