The starting line of a hyperlink?

In my php script, I created a constant variable that defines the base url to be placed in my hyperlinks, but is it really necessary?

Here is an example of what I mean.

I have it:

 // base url is only defined once and reused throughout
 define("__BASE_URL","http://localhost/test1/");
 print '<a href="'.__BASE_URL.'index.php?var1=open/>Open</a>';

(I have many of these distributions throughout my script.)

I tried this and it works:

 print '<a href="index.php?var1=open/>Open</a>';

So how is this the right way? I noticed that the second method works even when loading images, css and javascript files.

+3
source share
3 answers

, . URL- ( href="index.php" href="./index.php"), , .

URL- , , URL- ('/'). , , script //admin, - - .

, , , , , . , , , , .

.

, - script , URL- , (, script , ..). Apache mod_rewrite.

+3

. __BASE_URL . , index.php , , index.php.

__BASE_URL, , (.. , index.php).

- . :

print '<a href="/index.php?var1=open/>Open</a>';

, http://localhost/index.php.

+1

, URL-. ? URL-, , .

0

Source: https://habr.com/ru/post/1754677/


All Articles