Copy website folder and contents to Apache web server - html

I just started setting up Apache web server to try and test a website I am building. After installing LAMP (I'm on Ubuntu 16.04, if that's important), I copied a folder of HTML and CSS code that I had to test. Here is the folder's contents:
Main folder: testsite
Subfolders: articles, images, CSS, HTML, scripts
Contents:
articles -> .docx files
images -> .png files
CSS -> .css files
HTML -> .html files
scripts -> .py files, but one .html file too
When I went to test the Apache web server, it gave a 404 not found. I'm absolutely clueless as to what could be the answer. I tried renaming the maincode.html file that I had to index.html and putting it in the testsite folder, but it didn't change anything. Is there anything I need to do to fix this?
Here's a screenshot of the 404 Not Found page, with the Developer Console open (in Chrome)
I'm not sure what other information I need to provide, but I'll gladly give any info you need.

Make sure your testsite's conf file has the DocumentRoot property set to the path to your testsite folder. The conf file is probably /etc/apache2/sites-enabled/000-default.conf.

Related

apache2 not serving css file despite showing file in directory

I have a website I am trying to host, but for whatever reason, apache2 is refusing to serve the css file I have for my website. I have not change any settings and everything is completely default. I installed apache in the past 2 weeks so everything is clean and fresh.
All I did was copy all the files generated by jekyll from the _site folder and put them into /var/www/html on my server. now, when I go to my website, I can see all the content and the html loads correctly. The links work, images work. but there is no css styling available.
Because the default settings on apache arent that good, i can browse the folder contents. for example, my css file is store in /var/www/html/assets/css/style.css. So, when I access the website by going to https://mywebsite.com/assets/css, I can see the file structure and apache shows that I have a css file in there. but, when I try and click on that file, I get a
Not Found.
The requested URL was not found on this server.
----
Apache/2.4.52 (Ubuntu) Server at xxxx.com Port 443
All other files can be browsed in the folder structure and every file appears to be present, its just the pesky css file that will not load.

Downloading file from ubuntu server through html

I have my domain pointing at a ubuntu server hosted by amazon ws, and I have my index.html file that gets loaded when someone makes a request to my domain, in the same folder of that index.html file I have another file, and I would like to make it possible to download it from my website. How can I achieve that? I tried with an iframe tag, and giving it src="./myfile.jpg" but the server tries to look for it at www.mydomain.com/myfile.jpg and it can't find it there. Can anyone give me any suggestions?
Btw my files are inside /var/www/html folder, which from what I understood is the default folder for public files on ubuntu.

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.

404 page not found - Go rendering css file

I'm currently working in Go. I created a web server on my local machine. I followed the instruction on this page Rendering CSS in a Go Web Application
but I'm still getting the 404 error that the program can't seem to find where my css file is. My directory is as follows.
In src folder contains css/somefilename.css, src also contains server/server.go.
The code inside my server.go file is as follows.
http.Handle("/css/", http.StripPrefix("/css/", http.FileServer(http.Dir("css"))))
When I go to localhost:8080/css/ I get 404 page not found. I'm also using templates to render the html code. The templates are in the folder
src/templates/layout.html
the html code is as follows:
<link rel="stylesheet" type="text/css" href="../css/css490.css" />
Since you don't specify full path for the css folder just a relative one, whether your css files are found depends on the folder you run your application from (the working directory, this is what relative paths are resolved to).
For example if you start your application from your src with go run server/server.go it will work. If you start it from your src/server folder with go run server.go, it will not work. Also if you create a native executable from your app which is put into the bin folder and you start that from the bin folder, this also won't work because the css folder is not in the bin folder.
Either start it with go run server/server.go from the src folder, or copy the css folder to your bin folder and start the executable from the bin folder and it should work (but in this case you also have to copy other static files like html templates).

Html, external CSS link fails on Linux

I know similar questions have been asked but cannot see why our external css link doesn't work on Linux. The folder structure on both Windows and Linux is:
/
/static
/css
style.css
/img
/js
/html
index.html
The index.html links to style.css with:
<link rel="stylesheet" type="text/css" href="../static/css/style.css" />
It works on Windows but fails on Linux with a 404. This would imply that the /static folder and sub-folders don't have the correct permission but they actually have identical permissions as the /html folder. If all the /static content is placed in the /html folder then it works.
Has anyone come across a similar situation or know what the problem is?
Are you using mod_rewrite ? It has to be a server config issue. Make sure it is configured right
To be sure the path is ok, open index.html on the browser and check the path of css file from the page source there.
The problem can probably be permission on the css file.
The user apache ir running on must be able to read the file, otherwhise it will fail to load it
you can try running:
chmod a+r style.css
to add read permission to everyone on that file, or:
chown [user]:[group] style.css
to change the owner of the file to the user and group apache is using.
You can also check which user apache is running on in this question Finding out what user Apache is running as?
By default it usually is apache user and apache group.