简体   繁体   中英

images and css not loading on local wamp server using PHP

I have ran into a problem where by using /js/filename.js or /images/image.jpg etc is not loading anything on my WAMP Server. What it seems like is that its not getting the base url properly here. Screenshots will give you better idea.

加载文件

展示

Trying to reference the files with "/" in the start but it fails to load anything. I need to have it because i would be working with URL Rewrites so in that case it should load the files from there. Please let me know about any wamp server setting that is causing this issue.

Regards.

You are referring to your files with a root-path like " /my-file.txt " (ie having a slash at begin), which would result to " C:/wamp/www/my-file.txt " being requested.

Change all your paths to be relative paths, for example to " ./my-file.txt " path (ie with both dot and slash ./ ),

That would change the file request to something like " C:/wamp/www/my-project/public/my-file.txt " (if your HTML file is in public directory that is).

Actually I would not recommend you using relative paths like ./myfile.txt or something else, as it can get somewhat messy when you try MVC in your code.

Instead I would recommend you set up a virtual host on your wamp machne.

Here you can read more about setting up virtual host in wamp https://john-dugan.com/wamp-vhost-setup/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM