link file extension correction - html

I was just crafting some html for a webpage on a local server on my mac. I added a link to a stylesheet stored on my local server, but forgot to add the ".css" file extension in the href attribute. I didn't realize my mistake until I uploaded my files to an externally hosted server--because somehow the stylesheet could be found without the extension on my local server, whereas when I tried to load the page from the external server the extension was not assumed and my styles didn't load.
What entity figured out my error and corrected it locally, and why wasn't my error corrected when the page was hosted externally?

It could be that your local web server is serving the file up as text/css and the external one is not. What happens if you use TYPE="text/css" inside your LINK tag to the CSS file? That should force it to interpret the linked file as text/css.

Related

Image not showing in browser on local server (Live server extension) but shows when opened from explorer

I am having problem in HTML . My Image is not showing in browser (Firefox) when html file is opened through live server extension (VS code).It throws a Security error that html file can't link to image. I want to use image as background.
My html file is folder in D: drive.
Path = D:/myhtml/index.html
And my image is in F: drive
Path = F:/mountain.png
my img tag is
<img src="f:/mountain.png" alt="mountain"/>
But when I open html file directly from file explorer image shows up.
Please help to solve this problem.
Live server in made to behave like a real web server (one that is online on the web, called via http(s), and does not have access to your local hard drive file system "the Windows way" with F: etc.
Going to F:// is only possible on your own machine and will never work online. Browsers have built in a way for you to browse your local files like that. Web servers don't have this feature.
Use HTML file paths, meant for the web server:
Absolute path: https://example.com/images/mountain.png (path to an online destination which could be another domain than yours)
Relative path: images/mountain.png (relative to where your html file is located on your own web server)
Relative path to a folder outside of where your html is located: ../../etc/images/mountain.png

Mediawiki: Links to open local files on the server doesn't work

I have MediaWiki installed on a synology server. I would like to create a link on the wiki that would allow opening of files on the same server.
Here are the steps I did to achieve this:
Added $wgUrlProtocols[] = "file://"; in LocalSettings.php
A test file on the server: file://myServerName/path/to/file/test.txt. Putting this URL in my chrome browser directly opens the file.
Create a page in MediaWiki with a link to this file using [[file://myServerName/path/to/file/test.txt]]
When I click on the generated wiki page, nothing happens. However when I hover on top of the link, it shows the correct URL.
Can someone please point out what additional steps I need to do to get this working?
The file:// protocol points to the file on your computer. I'm not fully sure, but I think you cannot use it to retrieve file from a different machine (read my comment below about samba shares).
From quick research it looks like Chrome browser blocks requests with file:// protocol, But browsers like IE should allow you to open those files. It is done because of security reasons so the malicious site cannot open local files without your permission. You might bypass that by installing a special plugin in Chrome (look for Enable file links)
Instead of using file protocol, make those files available via Synology WebStation, and then create links that point to the file via webstation (not via path on the server). With that approach, links attached on your MediaWiki pages will work as those will be regular links.
If you don't use the WebStation, you might also try with ftp:// links (use the FTP service), or link to samba shares - that's where the file:// protocol might work, but again - I'm not sure and I cannot test it as I do not use windows.
I think that the safest/easiest/fastest way is to expose those files via WebStation.
Source: https://en.wikipedia.org/wiki/File_URI_scheme
The file URI scheme is a URI scheme defined in RFC 8089, typically used to retrieve files from within one's own computer.

HTML and HTAccess

I have been struggling with this all morning and I have not had much luck.
I am trying to get the following stackoverflow post to work: How to remove .html from URL
Here is my file directory with the htaccess file:
Here is my code that works fine using .html
So I went into sublime text and posted the same code into a .htaccess file as shown here (also in my directory first pic):
I then changed my links and removed .html
But I get an error
If anyone could please tell me what I'm doing wrong I would be grateful! Been bashing my head on this all morning
.htaccess is a file used to control access for Apache web servers. It won't affect anything unless you're running and accessing an Apache server. From your screenshots I can see that you're directly opening a file from your hard drive.
Your browser is saying File not found because you're trying to access a non-existent file. The address bar in your browser should say this:
file:///Users/mikegeng/Documents/GitHub/MichaelGeng.github.io/index.html
.htaccess is used by Apache Webserver. You must install and configure an Apache Webserver and access your site through http://localhost for example.
Currently your .htaccess is completely ignored until your site is served by Apache.

Download a file from a server using HTML-page (Java, HTML)

I would like to download a file throw the link from my html-page.
I have this file in a folder on the server. I have shared this folder for all.
The path to my file, for example is:
//bogn/folder/spi.jar
If I enter the path
file://bogn/folder/spi.jar
directly to the browser URL - then downloading is going successfully.
As I need to download the file from the HTML-page I use link:
<a href="file://bogn/folder/spi.jar" download> Download JAR </a>
The browser asks the question whether to save the file and then ignore saving. I can see the error: Network error.
How I can fix this?
Thank you.
The path to the file needs to be publicly accessible. If, for example, your html file in in the root web directory, and your jar file is inside "folder" in the same directory, then this will work:
<a href="folder/spi.jar" download> Download JAR </a>
The similar issue: how to create an anchor to a file in remote server in html
So it seems in Chrome and Firefox it is not allowed to download the files such way from remote server.
I have found the solution: I start using Servlets in Java and successfully download the files from remote server to browser.
This link was helpful for me: http://www.journaldev.com/1964/servlet-upload-file-download-example

IIS not loading css file outside of website folder

I have an ASP 4.0 web site being served by IIS 8 that is in a folder outside of wwwroot. The site will load, but a css file that I am using is not being loaded (getting a 404 error).
Here's the folder path for the site:
C:/Sites/Test/"website I am using"
And the folder path for the css file:
C:/Sites/Test/sharedfiles/css/stylesheet.css
Here's the link I am using to connect to the css file (with spaces to get this to post)
< link href="~/../sharedfiles/css/stylesheet.css" rel="stylesheet" type="text/css" / >
This should load the css file, but it does not. I'd like to figure out how to get this working.
The Sites folder is shared for IIS_IUSRS and IUSR and permissions are passed down to the folders below, including the Test/sharedfiles/css folder.
The web site folder is what's selected by IIS for the website. I have Anonymous Authentication enabled for Application Pool identity and Static File serving is enabled.
I'd appreciate any other ideas on how to figure out the problem!
Make sharedfiles a virtual directory and establish a web site or a web application there and access your resources (css etc.) using a url. So in local host you would have http://localhost/sharedfiles/yourcss.css
Thats the correct way to do it - what you are trying to implement here is your own CDN.