Local urls vs Remote server urls

I’ve looked everywhere for a solution, but I can’t seem to find an answer.

I’m designing a website on my laptop running on my local server. When I include files within my code I must specify the root of my local server. When I upload the files to my web host the root is completely different. How do I fix my urls so that no matter where I’m accessing my code, whether locally or through a remote server, the url takes me where I need to go. I have something set up right now, but it seems sloppy.

I hope I explained it well.

Welcome to the forums, Stephen!

Can you provide an example? Are you referring to php include urls or http request urls?

Try this:

// common, constants, config.php



<?php
 defined('LOCALHOST') ?: define('LOCALHOST', 'localhost' == $_SERVER['SERVER_NAME']);

if(LOCALHOST):
  $XAMP = '/xampp/'; 

  define('PATH_IMAGES',   $XAMP. 'htdocs/afiles/images/');
  define('PATH_THUMBS',  $XAMP .'htdocs/asubs/subs-johns-jokes/thumb/');
else:
  define('PATH_IMAGES',   FCPATH  .'afiles/images/');
  define('PATH_THUMBS',  FCPATH  .'subs/thumb/');
endif;

// works on both LOCALHOST AND REMOTE
echo '<img src="'. PATH_IMAGES .'my_image.jpg" style = "width:123px; " alt="#" />';