I'm aware that doing so in HTML is as simple as this:
<link rel="icon" href="/favicon.ico" />
However, I have a PHP site, in which:
DirectoryIndex index.php
to direct the user directly to the main page.
I can't seem to find a way to get a browser tab icon.
What have I tried?
I tried to echo HTML inside index.php with the code, which didn't work. I also tried placing the line of code in some other working header HTML from within index.php. Google has nothing... literally.
The image is a .ico, called 'favicon.ico', is in root, and is recognized as a valid ico file.
Any help?
By default, you actually don't need anything in your HTML for a favicon. Simply having a valid favicon.ico in your root should be enough.
Sometimes, when changing favicon you need to clear your browser cache for that site. Also, try accessing the favicon.ico directly: http://example.com/favicon.ico and make sure you can load it.
Here's a good resource about favicons: HTML 5 Favicon - Support?
Related
Got a straange - but simple - problem. The problem is that the CSS file won't load, despite path being correct.
I'm doing a website, and using php to insert link to css in page body.
This line produce the path to css-files.
$css_path = $_SERVER["DOCUMENT_ROOT"].'/html/'.filename($title).'_id'.$id.'.css';
From resulting page source:
<link href="/customers/8/1/f/mattemannen.no/httpd.www/html/hva-er-matematikk_id5.css" rel="stylesheet" type="text/css">
Which reads correct to me, but css won't load.
I have an fully analogous setup for including html-files, which works fine.
However, If I use
$css_path = './html/'.filname($title).'_id'.$id.'.css';
instead of DOCUMENT_ROOT the CSS code loads.
Which brakes my code at another place btw.
Shouldn't DOCUMENT_ROOT give a valid path regardless of where code runs from?
EDIT:
**CONCLUSION: I MIXED TWO PATHS, OF THE PHP-CODE AND THE HTML-CODE. THEY ARE DISTINCT. ITS OKAY TO BE NOOB THANKS :)
I am not sure what exactly is broken and it's kinda hard to explain. My file structure looks something like this:
+bin
+css
-style.css
-fontawesome.min.css
+fonts
-FontAwesome.otf
- ...
+www
+comp
-header.php
-footer.php
-index.php
-otherpage.php
Both index.php and otherpage.php include header.php and footer.php at the top and bottom, the content is in between.
Requesting the domain gives me the index.php and requesting the otherpage.php shows that as well as expected.
Requesting the configured bin.domain.com/css/style.css shows the correct css-file.
However, and this is the problem: The Link-Tag to the css-files is in the header.php and the css is not applied. Going to the Inspector shows the link-tag and following the link inside that shows the css that should apply to the page.
Now, here comes the weird thing: Going to the Style-Editor Tab in the Firefox Devtools shows the CSS from fonts.google.com as one link-tag imports a font. This is as expected but nothing else is shown so I don't even know where the error is at. Any Ideas?
Requesting the configured bin.domain.com/css/style.css shows the correct css-file.
This might not be it but you say you are using the following
<link href="bin.domain.com/css/style.css" rel="stylesheet">
What if you change it to
<link href="http://bin.domain.com/css/style.css" rel="stylesheet">
I found the solution:
The website itself was loaded via https. The Stylesheets and assets however where linked with http. I regenerated the SSL-Certificate and made the bin-subdomain a https-one. This was also said in the console in my Firefox-Browser but I didn't notice that.
This also explains why the Google-Font-Link worked while the others didn't. It was a https-request instead of a http-one.
I just built a sit in Codeigniter, but when I click on a menu item the stylesheet breaks and it displays all of the content broken out on the page.
http://marciabrownproductions.com/
I uploaded it to a test server and all the links works perfectly.But when I uploaded the finished site ot my clients server the css issue starts. Is there something wrong with my clients server? Or is there a problem with how I coded the site? Why does it work on one server, but not the other.
Thanks!
First, I recommend using absolute paths instead of relative paths when referencing your assets. At the moment, they are being picked up with the index.php included.
So, let's say your link is http://domain.tld/index.php/home/actors, you should be calling your assets from their actual URLs - http://domain.tld/index.php/_/css/style.css would not work, for example. http://domain.tld/_/css/style.css, however, would work. (That's just a sample URL.)
I'd also recommend removing the index.php from your links, simply by using the htaccess RewriteEngine, and removing index.php from your app's config file.
Have a look at how your current source is being generated in a browser (right-click, View Source) to see what I mean.
Update:
Based on your comment, that may be an htaccess issue. Check to see if your hosting provider supports it.
In the meantime, put the index.php back in the app's main config file. However, leave your CSS asset link as it is. Make sure all your asset links look like this:
<link href="http://marciabrownproductions.com/_/css/styles.css" rel="stylesheet" type="text/css" />
<script type='text/javascript' src='http://marciabrownproductions.com/_/js/jquery.validate.js'></script>
<script type='text/javascript' src='http://marciabrownproductions.com/_/js/effects.js'></script>
<link href="http://marciabrownproductions.com/_/css/bjqs.css" rel="stylesheet" type="text/css" media="screen" />
<script src="http://marciabrownproductions.com/_/js/bjqs-1.3.js"></script>
Your images are broken because their links are also including the index.php/home. You need to make sure that that is taken out. (What are you using to generate your links anyway?)
I'm trying to make user friendly URL using mode rewrite.
My problem is, that after giving category like 'name' to my URL, when I call the page using new URL, it can't load the CSS file or images.
I have a link like:
localhost/mywebsite/project?id=22
New link is something like
localhost/mywebsite/project/22/myproject.project
htaccess code:
RewriteRule ^project/([0-9]*)/.*\.project$ /project.php?project=$1 [L]
(it might not be 100% right but I don't have access to my code right now so I just wrote this and it works fine on the original source)
My root directory is localhost/mywebsite/
and my CSS file is in css/style.css
localhost/mywebsite/css/style.css
my htaccess
localhost/mywebsite/.htaccess
and my project.php file is in
localhost/mywebsite/project.php
So in the project page I have access to CSS file by using relative path,
<link href="css/style.css" rel="stylesheet" type="text/css" />
but when I use rewritten URL page can't find the CSS file.
I can't use absolute path with domain name because I don't have domain yet! and it can be anything.
one way is to use relative path to domain as suggested on the similar questions
localhost/mywebsite/project.php
and when i run my script localy my root directory is
localhost
so css link should look like
href="mywebsite/css/style.css"
but when i go live i should change all links to probably something like
href="/css/style.css"
this seems like lots of work
For your local version add
<base href="//localhost/mywebsite" />
to the head section
and for your live versions change it to
<base href="//your.domain.here" />
reference at http://www.w3.org/TR/html4/struct/links.html#h-12.4
you have to define the base path or the server view path in the connection.php and whenever u want that path, make that global. then that variable will b called and the css or images will take the whole path.
for example
$SVP="http://www.example.com/"
global $SVP;
echo $SVP;
so
Insert an image into the same file with the same relative path as the css href link, load the page in a browser, right-click the image in internet explorer, click properties and you should see where the relative path actually points to.
i am new to a php site, only familiar with .net web forms sites.
i can't figure out how routing is working on this php site.
www.oursite.com/suggestions.php is to suggestions.php
www.oursite.com/suggestions also loads the php fine
www.oursite.com/suggestions/ loads the php, but no css is applied
www.oursite.com/suggestions/anything - anything that comes after the '/' is ignored and suggestions is loaded without css. so oursite.com/suggestions////// works, as does oursite.com/suggestions/2/2/2/2/whatever
i have searched but not found any good explanation on how this is working. can someone explain or provide a good resource?
thank you.
This is most certainly done using Mod_Rewrite, an Apache extension. You'll probably find a file called .htaccess in the public root, in which these rewriting rules are defined.
DouweM has the right answer as far as the friendly urls are concerned.
As for the CSS, it is probably because you are using relative URLs in your link tags:
<link rel="stylesheet" href="site.css"/>
Change those to absolute URLs and it should solve that problem:
<link rel="stylesheet" href="/site.css"/>
The reason for this is that the browser makes the request for the CSS based on the directory it thinks it is in, even though your URL rewriting is changing that. So, if the url is http://mysite.com/suggestions/ and you are using relative urls, the browser will request the css as http://mysite.com/suggestions/site.css which of course doesn't exist.
www.oursite.com/suggestions.php is to suggestions.php
www.oursite.com/suggestions also loads the php fine
You probably have a .htaccess file that first checks whether or not a file of that name exists, and if it does serves it, then, if it doesn't, tries to route it to a php script.
www.oursite.com/suggestions/ loads the php, but no css is applied
The / means your browser considers '/suggestions/' a directory. If suggestions.php outputs HTML that contains a relative <link> to a stylesheet, e.g. <link href="style.css">, your browser will request www.oursite.com/suggestions/style.css, rather than www.oursite.com/style.css as in the previous two cases.
www.oursite.com/suggestions/anything
Same as the previous case, your browser will request the wrong css file, since it considers '/suggestions/' a directory. (For a potential fix, take a look at Eric Petroelje's answer.)
As DouweM said, though, your best bet is to look directly at your .htaccess file and figure out what it does.