How can I get my Hostinger shared hosting server to execute .htaccess file in hidden /.well-known folder? - apache

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.

Related

Apache change favicon for certain directory

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.

Redirect subfolder requests to subfolder

I have a setup where I can only access the root of a domain (subdomains are not allowed due to restrictive firewall policies). Lets say the domain is www.domain.com, for testing i have a symlinked a folder in /var/www/testing that points to several html and css files. In these files, scripts and css are included like e.g.
<link rel="stylesheet" href="/css/app.css">
which will fail as apache looks for the file in www.domain.com/css/app.css while it resides in www.domain.com/testing/css/app.css is there a possibility with .htaccess or RewriteEngine to make all requests (for css and js files) coming from /testing/ also going to /testing/... like examplified above?
Try
RedirectMatch ^/(css/.+\.css)$ /testing/$1
This will redirect /css/file.css to /testing/css/file.css

Redict Apache Directory Index

I've got an Apache server, and I'd like to set it up such that when a directory is requested that does not have an index.html file (and thus, Apache would, by default, generate a directory listing), Apache instead redirects (ideally using HTTP code 303) to a given url.
Unless absolutely necessary, I'd like to stay away from going outside Apache (for example, by having Apache load a php script which writes the headers manually). This is an otherwise static site, and I'd like to avoid having to introduce scripting languages into the mix.
Also, note that this post doesn't solve my problem since all of the proposed solutions use external scripts.
So I figured out that by using a combination of HTML meta refreshing and JavaScript redirection, I could cover almost all browsers in use and still have a static file. So what I did was this. In the apache site config, I put a directive that told apache to first look for index.html files, and if that failed, use a site-wide /no-index.html:
<Directory /path/to/web/root>
DirectoryIndex index.html /no-index.html
</Directory>
no-index.html, then, contained the following:
<html>
<head>
<meta http-equiv="refresh" content="0; url=/">
<script type="text/javascript">
window.location = "/";
</script>
</head>
</html>
(in this example it redirects to the web root, /, but you could replace that with whatever url you wanted)
See here for an explanation of what the <meta> tag is doing.

file does not exist c:/wamp/www/favicon.ico in apache error_log

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.

css was not loaded because its MIME type, "text/html", is not "text/css"

I got this error while working with web app.
This is my master page
<head runat="server">
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
This is the error:
Error: The stylesheet http://localhost:55381/Login.aspx?ReturnUrl=%2fStyles%2fSite.css was not loaded because its MIME type, "text/html", is not "text/css".
Source File: http://localhost:55381/Login.aspx
Line: 0
Looks like your code is requiring a login to access the CSS stylesheet, and returning a HTML login page instead of the CSS.
To verify, try pasting the URL to the stylesheet into your browser, for instance http://localhost:55381/Styles/Site.css - if you get a login page instead of CSS, that's what you need to fix.
Try this:
<location path="~/Styles">
<system.web>
<authorization>
<allow users="*"/>
</authorization>
</system.web>
Where Styles is the folder that contains style sheet. I solved it this way
#DavidPrecious gave a great answer that led me to the solution.
In my case, the local computer's Users group needed to be given Read permissions to the c:\Inetpub folder in order to allow the static content to be delivered properly.
This is more likely an issue at your server side. You request style sheet page Styles/Site.css from the server of type text/css, but your server might be responding to this request with test/html. I had this issue when my server was running in Python and my server was replying to requested css files with header text/html (as that of my index.html file). I re-arranged my server code and assigned the correct headers to its corresponding pages and my issue got resolved.
Another possibility: you've modified your .htaccess file to serve css as html. Maybe something like this, for example:
<filesMatch "\.(htm|html|css|js)$">
ForceType 'text/html; charset=UTF-8'
</filesMatch>
You will want to remove the css from the first line if you've done this.
For me it was an nginx configuration problem, in the file where you declare the path to your static content. I had to move /etc/nginx/mime.types out of the http{} block and further down into where I was serving the static content from. It could similarly be an apache or IIS problem as well, depending on your technology stack.
location / {
include /etc/nginx/mime.types;
root /path/to/static/content;
try_files $uri /index.html = 404;
}