Relative URLs question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hora
Forum Newbie
Posts: 9
Joined: Mon May 05, 2008 10:17 pm

Relative URLs question

Post by hora »

Hi everyone,

I did a search for this here and on google and still couldn't find what I was looking for, and hopefully someone here can help me.

In PHP, how do you specify a relative URL that goes to the 'root' directory of your site?

I know that in HTML, if you were here: "www.mysite.com/images/index.html"

and in there you had a link that looked like this: "/files/file.html", it would go to "www.mysite.com/files/file.html"

How do you do this in PHP?

Thanks!
LSJason
Forum Commoner
Posts: 45
Joined: Mon May 12, 2008 4:43 pm

Re: Relative URLs question

Post by LSJason »

It's done the same way if you are linking. However, if you are using it in the context of a PHP function (include(), require(), etc.), the leading slash ("/") refers to the root of the file system, not the URL. To form a relative file system URL, you would replace the leading slash with ./
Post Reply