I need to set images from the Magento media folder but index.php keeps getting in the way and since I'm going to be moving this dev site to another production URL, I can't just use hard paths in this case.

In Wordpress/Drupal I can set a link like <img src="<?php echo home_url(); ?>/media/image-name.jpg" /> but I can't find anything similar to that for Magento.

I'm needing this for the static blocks section if that makes a difference. When I try to set relative links to http://mysite.com/media/image-name.jpg I end up with http://mysite.com/index.php/media/image-name.jpg which of course results in 404.

What do I need to put in static blocks that will reference the main site without the index.php?


2 Answers 2


Well, the canonical way to get the media url is:


so you in phtml you can do

<img src="<?php echo Mage::getBaseUrl('media'); ?>image-name.jpg" />

but in static blocks you need template syntax:

{{media url='image-name.jpg'}}
  • Excellent. This was very helpful.
    – o_O
    Commented Jun 18, 2014 at 7:14

You can use

<img src="<?php echo Mage::getBaseUrl(); ?>media/image-name.jpg" />

Take a look on this article. It lists all type of url methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.