如何正确设置链接和其他资产的URL [重复]

This question already has an answer here:

I want to use the full URL for the location of my css, js, and image files in my header.php file. So that when the header.php file is called from another folder directory, it doesn't break the link.

However, I want the site to be accessible by http and https, set by the user in their profile settings in the web application.

I started to write some code below of the solution but I'm not sure if this is the correct way of handling this.

config.php

<?php
// use https
$use_https = true;
?>

header.php

<?php
if ($use_https == true) {
   $proto = "https://";
} else {
   $proto = "http://";
}
?>

  <a href="<?php print($proto . $_SERVER["SERVER_NAME"]); ?>/some-folder/">Link</a>
</div>

The easiest way is to just do:

<a href="//<?php echo $_SERVER["SERVER_NAME"]); ?>/some-folder/">Link</a>

Or since it's on your own server, just:

<a href="/some-folder/">Link</a>

Make sure to include the initial slash, so that it is relative to the root of your site, and not to the current page (this will prevent the link from breaking).

That being said, if your site works with https, you are probably better off just always using https, since you don't really have performance concerns anymore.