I'm having a problem with apache that it only looks in the root directory for favicons. I need a separate favicon for a specific directory on my webpage. Below I will draw an example
- favicon.ico
- index.html
- / Folder
- favicon.ico
- index.html
- index2.html
I want /index.html to have a favicon of /favicon.ico and I want /Folder/index.html and /Folder/index.html2 to have a favicon of /Folder/favicon.ico. (Edit: I do not want to specify at the top of each file, there are too many to make that practical)
I tried just putting a favicon.ico inside the sub-folder but it didn't do anything different. Thanks
Simply add the following code to the <head> element of each HTML file were you want to change the icon:
<link rel="icon" href="http://example.com/favicon.png">
The Path needs to be adapted in the code snippet
What is important is that you have this snippet in your HTML files and then you just update the path to the icon you want.
This link might help you:
https://www.javatpoint.com/how-to-add-a-favicon-in-html
Also if you search google for your problem you will get many docs and examples.
Related
I am on a Hostinger shared plan, trying to set a CORS header on a single TOML file that MUST reside in the public_html/.well-known folder. I have an .htaccess file in the ".well-known" folder but the Apache server will not process it.
However, if I rename the ".well-known" folder to "well-known" (just removing the period), the .htaccess file works and I can set whatever headers I want for files in that folder.
At this point I have deleted my entire site and replaced it with an extremely simple one in order to try and make this work.
The current file structure is as follows:
public_html
/.well-known
.htaccess
test.toml
/well-known
.htaccess
test.toml
index.html
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Apache Header Test</title>
</head>
<body>
Apache Header Test
</body>
</html>
.htaccess (identical in the ".well-known" and "well-known" folders)
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
test.toml (identical in the ".well-known" and "well-known" folders)
Apache Header Test
When I navigate to /well-known/test.toml, the response is served with the CORS header set and a content-type of "text-plain", and the toml file contents show as plain text in Chrome, which is the desired and expected behavior for both folders.
However when I navigate to /.well-known/test.toml (with the period), there is no CORS header, it shows a content-type of "application/octet-stream", and the toml file downloads instead of showing in the browser.
What exactly is happening here and how can I fix it? Thank you!
After finally asking the right question to Hostinger (thank you MrWhite!), they confirmed that making changes to the /.well-known folder is not possible on a shared hosting plan. Here is the official response I received:
The .well-known directory is server-default, so that is why overriding and making changes to it is not possible on a shared hosting plan, as important data/information is stored there.
To make meaningful changes in this directory, you would need root access, which is only available on our VPS plans.
Edit: CONFIRMED NOT POSSIBLE
I have a static HTML site where all references are absolute, based on the document root being /
eg.:
<img src="/images/myimg.jpg>
<link href="/styles/main.css">
and so on...
For testing purposes, I need to be able to put the site inside of a sub-directory and point all paths to that directory.
ie., the paths need to effectively be this:
<img src="/sites/myvsite.com/images/myimg.jpg>
<link href="/sites/myvsite.com/styles/main.css">
and so on...
The catch is that my .htaccess file needs to be in /sites/myvsite.com to because I can't modify files in the document root.
Is this possible with mod_rewrite or some other .htaccess facility?
There are always the log showing: file does not exist c:/wamp/www/favicon.ico in apache error_log. I used wampserver, why?
This happens because (almost every) browser searches for a favicon by default. If the accessed page don't inform a valid URL for it, Apache uses the root directory.
You have two choices. You can create a website icon for each of your websites, or you tell Apache not to log that event as an error message.
If you choose the second option, add the following code to each VirtualHost, or at least the ones which don’t have a favicon file:
Redirect 404 /favicon.ico
<Location /favicon.ico>
ErrorDocument 404 "No favicon"
</Location>
Or, you create an empty file with the name “favicon.ico” in the directory root of Apache (for exemple /var/www/ , but no favicon will be shown by the browsers for your site).
Do you have a reference to the favicon.ico file in your HTML source?
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
Even if you don't, many browsers try to access this file anyway when visiting a new page. Favicon is used when adding the website to favourites/bookmarks. Some browsers (for example Firefox) also display favicon on the website's tab on the top of the screen.
Your best bet would be to simply add an favicon.ico file with a 16x16 icon to the c:/wamp/www/ directory.
favicon.ico is the image that is showed next to the url in the address bar. Every browser search for it. For example the StackOverflow logo in this page.
see this http://nfolamp.wordpress.com/2010/06/28/apache-favicon-ico-does-not-exist-yes-its-truly-annoying/ (dead link)
the contents of that link are in the voted answer https://stackoverflow.com/a/11099560/876038
Try restarting your browser. I thought I had a major problem with this, but as it turns out, mozilla just caches sites favicons. Restarting it fixed the issue.
i got another problem.
i have an own apache server (XAMPP) on my computer. The URL in my browser looks like
http://localhost/pageExample/index.php
i use a .htaccess file to change my url from ?action=home to home.html
The problem now is, that the path to all images, css files etc be wrong. They looks like
http://localhost/images/logo.jpg
I think, there is something wrong in my .htaccess file... i tried <base href="http://'.$_SERVER['HTTP_HOST'].'/pageExample/">.. this works ..okay... but some scripts with extern images doesnt work.
My .htaccess file looks like:
RewriteEngine On
RewriteRule ^home.html$ /pageExample/index.php?action=home [L]
(By the way... the problem came since I created the .htaccess)
How to change this?
Thanks!
This is a common problem when you start rewriting URLs but website is not coded accordingly. In your HTML/CSS, when you are referring to images/scripts/css resources you most likely have something like this: <img src="images/hello.jpg" />. Bacuse you are rewriting URLs you need to alter the resource URLs as well -- in the above example resource is linked to the path of the HTML file (relative path) -- you need to make the path absolute. For this -- add leading slash before resource references:
change
<img src="images/hello.jpg" />
to
<img src="/images/hello.jpg" />
Let's say you have the following setup.
You have a server with the basepath set to the normal webroot.
The server has files in the following structure
/projects
/some-unique-id
/index.html
/images
/some-unique-id
/index.html
/images
Is it possible to have a .htaccess file somehow redirect the paths so if index.html has absolute paths they work.
For example if index.html contains /images/foo.gif can this magically become /projects/some-unique-id/images/foo.gif
The equivalent of the base html tag.
This is part of a CMS deliverable previewing system so I am restricted to not changing the HTML code.
Is there anyway to address this in an .htaccess file?
If each index.html contains <img src="/images/foo.gif"/>, the browser will request that URL and there will be no way for the server to know which page caused the request since the requests will be identical regardless of the originating page.
There is no way to do this with mod_rewrite unless you try to check the Referer header, which would be unreliable at best.
You will have to change your HTML markup to solve this. Using relative URLs seems like it would solve your problem.