This must be a simple fix, but I just can't figure it out!
I am including the header via PHP into each new page, the header contains the CSS and scripts etc.
Only problem is since the page is in a different directory, when I link to the header like ../header etc it looks fine but the included scripts, are the included via a short URL eg /js/script.js
Which means on the page (in another directory) the scripts do not work!
I'm finding it hard to explain but take a look at this:
http://www.healthygit.com/
If you view the source all the scripts link fine.
Now look at this:
http://www.healthygit.com/fitness/running.php
If you try to click on a script to view it, it takes you to a 404 or in this case 302's you to the homepage.
Easy peasy, your source for the scripts, stylesheets etc. should have a /
in front of them, that way the header file will always refer to the files from the root of the site.
Ie this:
src="js/whatever.js"
Should become
src="/js/whatever.js"
This way it will always look for the files from the root of the site. The same applies with CSS files, ie /css/whatever.css
.
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.