Skip to content

Instantly share code, notes, and snippets.

@julienbourdeau
Created May 23, 2017 17:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julienbourdeau/ad4fadd9bbf9f99c46f8f8e28fb14ffc to your computer and use it in GitHub Desktop.
Save julienbourdeau/ad4fadd9bbf9f99c46f8f8e28fb14ffc to your computer and use it in GitHub Desktop.
[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
Copy link

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