yeah correct but that shouldnt matter, works both ways but I tried both and both gave the same outcome unfortunately :(
CSS BG image not found, but found when clicked on link
Hi guys, as the title says...
when I use background-image:url('') it says the image is not found but when I click on the image link in the source code, it shows me the image.
Can anyone explain me what is wrong?
Also... to see my website I have to go to www.mysite.com/public and when I try the .htaccess method found on internet
RewriteEngine On RewriteRule ^(.*)$ public/$1 [L]
it doesnt work, it gives me a route error.
Hope someone can help me out, i'm using Laravel 5.4 :)
P.S. see the screenshot... even outside of CSS and just with a "style" attribute on my div the browser says "cannot find the image" but when I go to the link, the image is found!!!
https://s4.postimg.org/yroyk7nwt/wtf.png
website is not located in my root though its in a sub folder e.g.
mysite.nl/testfolder/
As a side note, your css scripts should be included at the top of the page, not the bottom
So a couple things now that i look at this more.
You shouldn't have to access your site through /public. What kind of hosting are you using? You should point your domain to the public folder.
Once that is working, you should be able to just use a relative url for the image itself, so like:
background-image: url('/images/slider-ad-1.jpg');
At the bottom increases the page load speed, been doing it for years ;) but for this example ill move it to the top then :)
About the public folder... I meant the "public" folder in Laravel. After deploying it, it automaticly comes as
root\public\index.php
and thus to see the website I need to go to www.mysite.nl/public/ otherwise I wont see anything. See my folder structure in the screenshot. This is how Laravel comes out of the box.
See the link below for my FTP folder structure. I have no clue on how or what to change in the .htaccess to make everything visible without typing in "public" in the URL.
/domains/mysite.nl/htdocs/www/projects/zoekmachine
image: https://s11.postimg.org/wb2zazcqr/laravel.jpg
I just noticed when I write in my HTML :
img src="image_url_here/image.jpg"
it cannot find the image either!?.... but that only happens with images on MY server... i.e. http://www.mysite.nl/image1.jpg but when I use a external image for example
then it does display correctly.... anyone has a clue what this can be?
A link to a live version can be found here... then you can see exactly what I mean :)
[link removed since website is being moved]
Let me clarify a little bit about the public folder thing.
If you are using shared hosting like godaddy, you might have an option to specify which folder your application lives in for your domain to point to. Instead of pointing it to your root folder, point it to: /domains/mysite.nl/htdocs/www/projects/zoekmachine/public
If you are using a VPS like digital ocean or aws, if you are using nginx, you would specify the same thing on the server level with your ngxin configuration, like so:
server {
listen 80;
listen [::]:80;
server_name mysite.nl;
root /domains/mysite.nl/htdocs/www/projects/zoekmachine/public;
My point is, your .htaccess file only works if you have configured your domain or server to point to the public directory
well, dont think that is the issue... I have multiple sites on my domain (not shared hosting) and it works flawless, has been for 13+ years... only since this week with Laravel I had this issue (im new to Laravel)... so I think its either Laravel or something like that related cause everything else is working just fine :)
Thanks for your fast replies!
Edit: Ill just buy a new domain for it instead of using a subdirectory, that will work fine... its not shared hosting and I have zero access to the config of the server so I couldnt change anything even if I wanted lol. Nevertheless, I'll let you know if this solved the problem when I transfered my Laravel installation over to the new domain where I will install it into the root directory.
so, a couple of things. You will always have issues whilst you have public in the url. your #1 priority should be to eliminate that
The other thing to note is that background images are relative to the location of the css file unless you start the url with a backslash indicating that the background image is an absolute path from the root
What does your network tab look like in the Chrome Inspector. Does it say 404 not found? Maybe it's a CSS issue, did you try using a placeholder image from online services to test it out? Could be permissions issue as well, try visiting the image URL in Incognito mode, maybe image is cached locally for you but might not work for anyone else.
Hope that helps.
I put it on a new domain, so you can see a live version :)
xxxxxx
same stuff happens. Its not shared hosting, I have not changed .htaccess files or anything else. When I use placeholders from an external source, everything is already... only when using images from my local hosting they can not be displayed... this only happens in Laravel.
When I look into the source with my Instepctor it simply says "Image could not be found" but when I copy the link into my URL then I do see the image!...
In my network tab the images (local) are NOT displayed which is kinda weird...
images are located in the /public/images/ folder.
I found something about permissions online and checked it... this is what the file looks like:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
EDIT: Just found out (I know, should have sooner) that this only happens in a file loaded by BLADE. If I put it in my layout, images work fine! when I put it in a file that EXTENDS my layout, images simply do not work!
EDIT: I found out what is wrong... it are the images... so weird though! I have a couple of hundered images, they all wont display in Laravel or on any website... but if I open them in Photoshop, copy and paste them into a new image, save and upload it works.... I have no clue why because I have been using these images for years! but yeah, this works... :)
Thanks so much for all your answers guys! great community!
That simply because your images were in CMYK. Copy/pasting in a new one took the default setting in RGB. That is the only explanation I see.
Please or to participate in this conversation.