URL address can be relative to the server or to page. For a URL to a folder or on the Web server that you need to make a URL or on a server or a page. Each relative URL, together with the base URL is completely defines where the object.

If you have an absolute address, for example https://www.flyaga.info/wordpress with the image file named Image.jpg living in the image on the web, you can create a relative URL for the address, decide whether a URL on the address for the server or page.

For servers, the relative URL, use “Flyaga / Pics / Image.jpg” with the server name as the basis for the relative URL, which completely determines the location of the object. For the URL of the page on which you want to use “pics / Image, JPG” with the name and Theserver the web as a basis for the relative URL, which completely determines the location of the object. In the folder-relative URL, use “Image.jpg” with the name of the server, a web name and the name of the folder as a basis for the relative URL, relative address fully defines the location of the object.

Folder-relative URL can also be specified in another folder, for example, “Image.jpg” may be used if the document type to another top-level folder on the same network server. “..” a designation used to indicate a level above the current URL address.

How to convert the relative URL to its absolute path using PHP

Below you will find the simple PHP script to convert relative URL to the absolute path.

function convertreltoabs($rel, $base)
{
if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel;
if ($rel[0]=='#' || $rel[0]=='?') return $base.$rel;
extract(parse_url($base));
$path = preg_replace('#/[^/]*$#', '', $path);
if ($rel[0] == '/') $path = '';
$abs = "$host$path/$rel";
$re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {}
return $scheme.'://'.$abs;
}

That’s, all folks! :)

Leave a comment

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.