Root Relative URLs

/ Published in: PHP
Save to your folder(s)

For several reasons, including portability, reducing download size, and general code neatness, I like to make all links within a website root relative.

Copy this code and paste it in your HTML
  1. function make_href_root_relative($input) {
  2. return preg_replace('!http(s)?://' . $_SERVER['SERVER_NAME'] . '/!', '/', $input);
  3. }


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.