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 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 subfolder
  • 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 information</a>

The same applies to the use of image tags. In a define page or an EZ-Page, be careful not to start image URLs with a /.

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

The reason is, this will work when the site is at the top level, but it won’t work if the store is moved to a subfolder, which is common when setting up a test site.

If you don’t start the path name with a slash, it will work correctly, whether the store is at the top level or in a subfolder.

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

Still have questions? Use the Search box in the upper right, or try the full list of FAQs. If you can't find it there, 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 March 22, 2023 by Scott C Wilson (8ed4304).