How to write a link with a 3-level domain?

I have a website where I created 3rd level domains. In fact, these are folders on the server in the root directory. index, config, variables are in the root directory, the rest of the files are in folders. How to write a link to a 3rd level domain in the menu? I have this option now, but it’s not quite right:

<a class='at' href='/page/p1.php' target='_top'>Page1</a>
 <a class='at' href='/page/p2.php' target='_top'>Page2</a>
 <a class='at' href='/page/p3.php' target='_top'>Page3</a>
 <a class='at' href='www.doman.site.com/page/p1.php' target='_top'>Page1</a>

I would like the links to work when changing the server and domain.
Thank you.


Answer 1, authority 100%

<?
//  
$_ENV['L'] = array(
  'dom'      =>'www.site.com',
  'subdom1'  => 'dmn1.site.com',
  'subdom2'  => 'dmn2.site.com',
  'subdom3'  => 'dmn2.site.com',
  'dirAdmin' => '/admin/pages/',
  'dirInfo'  => '/info/'
  );
?>

<?
// 
$L = $_ENV['L'];
echo '<a href="http://'.$L['dom'].$L['dirAdmin'].'login.php">Log In</a>';
echo '<a href="http://'.$L['subdom1'].$L['dirInfo'].'">SubDomain #1 info</a>';
echo '<a href="http://'.$L['subdom2'].$L['dirInfo'].'">SubDomain #2 info</a>';
?>

Answer 2, authority 100%

There are options:

  • write all links relative, remembering which page is located
  • get yourself a file with constants (for example, $admin='/myadmin/'; $db='/db/data/'and the like. And in the code, just write href="'".$adnin."index.html'". In this case, when moving, you will only need to correct one file. At the same time, if the link to a file is repeated very often, then you can create not only a link , and along with href and title.This can also greatly speed up development and reduce the number of errors.