Anchor <a> + Base URL Link

If I'm on a page, for example

http: //localhost/balibar.co/? dating = dating-articles-and-information

and I want to link the links to the base URL

http: //localhost/balibar.co

Is there a way to do this without hard-coding URLs?

I tried:

 <a href="/"></a>
 <a href="#"></a>

will use multiple domains for this page, so I don’t want to hardcode the domain name if possible.

+5
source share
6 answers
<head>
    <base href="http://www.google.com" />
</head>
<body>
    <a href="">Google?</a>
</body>

This link will now go to google.com

Here is the proof:

http://jsfiddle.net/3wXCJ/

HTML <base>, url , href. href src, , URL-, .

+6

, http://localhost/balibar.co/, (.) <a href="./"></a> , <a href="."></a>

(.) .

+5

, URL- URL-, HTML <base> tag <head> :

<base href="http://localhost/balibar.co/">
+4

HTML <base> .

<html>
<head>
<base href="http://www.yahoo.com/images/" />
</head>

<body>
<!-- Links to http://www.yahoo.com/images/ -->
<a href=".">Top-level link</a>
</body>
</html>

, href URL- , .,

+3

<a href="/"></a> , balibar.co .

<a href="/balibar.co"></a>

+1

, SEO, , .

because you have several domain names, I would use PHP to first find out which domain name is currently being used, and then write it by reference:

<a href="<?php echo 'http://'.$_SERVER['SERVER_NAME']; ?>">
0
source

All Articles