Relative URLs

The importance of relative versus absolute links

New Zen Cart users will often customize a file like includes/templates/responsive_classic/templates/tpl_modules_mobile_menu.php by adding an internal URL to their store with a full path. For example,

  <a href="">Important Pricing information</a>  <!-- NO! --> 

This is not a good practice. This URL will not work as expected in the following circumstances:

  • You move the store to a subdomain (
  • You change domain names
  • You work on a temporary or local domain
  • You work on an IP address during a hoster change

Instead, it is better to use a relative URL, which will always work.

  <a href="index.php?main_page=page&id=25">Important Pricing information</a>

The same applies to the use of image tags. In a define page, for example, it is common to reference an image starting with /.

<img src="/images/POINTS.jpg" alt="Get Points"></p>   <!-- NO! --> 

The problem is, this won’t work if the store is moved to a subdomain.

If you don’t start the path name with a slash, it will work correctly.

<img src="images/POINTS.jpg" alt="Get Points"></p>

Still have questions? No problem! Just head over to the Zen Cart support forum and ask there in the appropriate subforum. In your post, please include your Zen Cart and PHP versions, and a link to your site.

Is there an error or omission on this page? Please post to General Questions on the support forum. Or, if you'd like to open a pull request, just review the guidelines and get started. You can even PR right here.
Last modified August 18, 2020 by Scott C Wilson (cd02d11).