Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Matrich's avatar
Level 14

Error displaying images in subdomain

I have successfully deployed my laravel project to shared hosting (cPanel) and all seems to be working apart from the images. The images stored directly on the server e.g. logo.png don't show up and yet css files in the same public directory show up.

When I try to view the image directly via its URL, I still can't access it and gives me an error of "The image "http://..." cannot be displayed because it contains errors.

I have tried several alternatives which work locally but not when I upload.

< img src="/img/logo.png" width="100" /> < img src="{{ asset('/img/logo.png') }}" width="100" /> None of the above works and even when I try to access it via http://sub.domain.com/img/logo.png . It gives the error above

Could you please advise? Thanks in advance

0 likes
6 replies
Snapey's avatar

do you see /public/ in your page URLs ?

ghaith_atfeh's avatar

@Snapey I have a problem similar to this with subdomain, the css files are not loaded and when i go to this subdomain, it redirect me to /public, can you help?

Matrich's avatar
Level 14

No, I added .htaccess in the subdomain folder and added RewriteRule ^(.*)$ public/$1 [L] rule.

What perturbs me most is that the css files and js files are referenced properly yet the images in the public/img folder aren't.

TheRealJAG's avatar

Do you have a conflict in another RewriteRule?

I would keep testing at the URL level, once you get that working everything should fall into place.

Matrich's avatar
Level 14

There is only that RewriteRule. I have done this on two servers and I still get the issue.

Matrich's avatar
Matrich
OP
Best Answer
Level 14

It turns out that the problem wasn't with the RewriteRule but rather the ftp client uploading the images with ASCII format. Laravel doesn't seem to pick those images so I re-ftped them with binary format and everything is working fine.

I hope this can help someone else.

Please or to participate in this conversation.