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.
Related
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.
I'm using create-react-app which is serving its files from the /build folder. Typically Github Pages looks at index.html at the root level, but I'd like to direct it to look at /build for deployment.
I've tried to add "homepage": "/build" inside my package.json configuration, and Github Settings says it's deployed via <username>.github.io. However, the site just shows my README.md file.
Any help is appreciated :)
The problem here is that this is a Web Browser issue, and not a Host issue. When you visit a webpage your browser always looks for the index.html file at the URL so localhost:8080 becomes localhost:8080/index.html.
This means that there are a couple ways to fix this. You could create an index.html file in your root directory and then have that serve up the scripts in the build folder like <script src="build/main.js"></script>
You could also go through the pain and suffering of manually adding /build to the end of the URL. But you don't want users to have to do that, so you could write a script to redirect you there.
Good luck!
I am running an Apache web server on a machine running Centos.
THE PROBLEM:
When I run the server, everything works fine and I can see the welcome page. The problem occurs when I try to put in an index.html file I previously created into the /var/www/html directory. When I do this I get the error: Forbidden you do not have permission to access index.html on this server. The weird part is I created an index.html file as root in this directory and it works. It was just a simple test html file:
<!DOCTYPE html>
<html>
<head>
<h1>Hello World</h1>
</head>
</html>
This works. So I tried copying the html text from the original index.html to the one I specifically created in the /var/www/html directory and that works. The only problem here is now I have to create lots of new files in the html folder and copy the contents of the old files into the new ones. Also, how would I get images to work? And Hence, my question. So what is the difference between moving files to a directory and creating them there?
Note
I know I have set the server up correctly because I am able to access it from another computer so I don't think there is an error with the httpd.conf file. Also, I am not using a .htaccess file. The permissions on each file is the same, only one works and one doesn't. The permissions I have tried are -rwxr--r-- and -rwxrw-rw- and -rwxr-xr-x. I have also changed the owner of the files to be the same. I have tried changing the owner to apache and to root. No luck.
Thanks for the help
Moving files retains the SELinux file context assigned to the file when it was created in its original location. Copying it recreates the file anew in the new location, giving it the appropriate file context for that location.
The appropriate file context can be restored on a directory and all files contained within by running restorecon against it. See the restorecon(8) man page for details.
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).
I have installed XAMPP , there is a htdocs folder and inside it index.html file ,
when I try to open it in my browser through http://localhost/xampp/htdocs/index.html it says
unable to connect to localhost .
what is wrong ?
instead of
http://localhost/xampp/htdocs/index.html
try just
http://localhost/index.html
or if index.html is saved in a folder in htdocs then
http://localhost/<folder-name>/index.html
htdocs is your default document-root directory, so you have to use localhost/index.html to see that html file. In other words, localhost is mapped to xampp/htdocs, so index.html is at localhost itself. You can change the location of document root by modifying httpd.conf and restarting the server.
Start your XAMPP server by using:
{XAMPP}\xampp-control.exe
{XAMPP}\apache_start.bat
Then you have to use the URI http://localhost/index.html because htdocs is the document root of the Apache server.
If you're getting redirected to http://localhost/xampp/*, then index.php located in the htdocs folder is the problem because index.php files have a higher priority than index.html files.
You could temporarily rename index.php.
You need to start your Apache Server normally you should have an xampp icon in the info-section from the taskbar, with this tool you can start the apache server as wel as the mysql database (if you need it)
All created by user files saved in C:\xampp\htdocs directory by default,
so no need to type the default path in a browser window, just type
http://localhost/yourfilename.php or http://localhost/yourfoldername/yourfilename.php this will show you the content of your new page.
You should simply create your own folder in htdocs and save your .html and .php files in it. An example is create a folder called myNewFolder directly in htdocs. Don't put it in index.html. Then save all your.html and .php files in it like this-> "localhost/myNewFolder/myFilename.html" or "localhost/myNewFolder/myFilename.php"
I hope this helps.
I just put an index.html file in /htdocs and type in http://127.0.0.1/index.html - and up comes the html.
Add a folder "named Forum" and type in 127.0.0.1/forum/???.???