Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[Magento2] Make sure image are served from /pub/media AND /media
# If your Apache already serve request from the /pub dir
# This will allow malformed URL to reach their destination.
# Alias /pub the pub/ dir on disk
# Replace path with your actual path
Alias "/pub" "/var/www/public/pub"
location /pub/ {
alias /var/www/public/pub;
}

If you use Magento from the root dir you might want to make sure all your images url are valid. There are some known issue with this but it's generally considered a good practice.

Maybe you have image path like example.com/pub/media/image.png instead of example.com/media/image.png.

The best way to fix this is to tell your server to ignore the /pub in the URLs. Do not set redirection!

Find above the lines to add to your server configuration.

@pixiemediaweb

This comment has been minimized.

Copy link

@pixiemediaweb pixiemediaweb commented Jan 23, 2018

Hi, you're missing a trailing slash on that nginx config;

location /pub/ {
alias /var/www/public/pub/;
}

;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment