I had my site in the m...">

Html <base> not working with href on localhost

My links look like

<link rel="stylesheet" href="/utils/style.css" />

I had my site in the main directory, so this is not a problem, but when I moved all my files to / dir / I, create the base tag:

<base href="http://localhost/dir" />

But that will not work. It works fine though, if I use the online address on my website

<base href="http://www.my-website.com" />

what's wrong?

+4
source share
4 answers

Dir is a directory, so you need to add / after it, also you do not need to use the base to have a clean url ... If that is what you are trying to do.

<base href="http://localhost/dir/" />

+3
source

Pawel you can use a base tag like:

<base href="http://localhost/dir/" >

, - :

<base href="/dir/" >
+1

dir - , /

Try

<base href="http://localhost/dir/" />

<link rel="stylesheet" href="utils/style.css" />

EXTRA

, URL-, .

-

# localhost name resolution is handled within DNS itself.
    127.0.0.1       dev.my-website.com
0

Pawel, " , URL- ...": , : URL: s , URL: s , , , . , ( ) , href base. ( .)

. . , URL-, <a href> <img src> .., (.. ) : mytoplevel-dir/mysubdir/myresource.xxx , , : myresource.xxx, , () (../subdir ../myresource.xxx). , URL: s , href base .

, , -): PHP base. $_SERVER["SCRIPT_NAME"] (.. , ). ( ). :

<?php require_once('../common/php/URL_Manager.php'); ?>
.
.
<base href="<?php echo URL_Manager::getCurrentServerAndContextPath(); ?>" />
.
.

, <base href> , / ( ), , . <a href>, <img src> <link href> ( , ).

<base href> , , , - , . <base href> p >

<base href> , , , <base href>, - , .

, .

, , , , base, , , , , :

<a href="<?php echo URL_Manager::getCurrentPath(); ?>#menuBookmark">

:

<a href="#menuBookmark">
0

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


All Articles