root folder linux server - html

I have inherited a site which the css links on all of the 100+ pages are relative to the root. For example they are
<link type="text/css" rel="stylesheet" href="/css/main.css">
Locally this is fine locally but remotely the .html file is looking at the root folder when actually the files are in
http://myserver.com/thesitefolder
is there a way to do this via .htaccess or another way? I think a sub directory would work but is there a qucik way to fix this?

Set up a DNS A-Record for thesite.myserver.com pointing to IP of myserver.com
Set up Apache virtualhost for thesite.myserver.com pointing to the root directory
Now your site folder (for the new virtual host) is the root folder

Related

Showing a link to a folder on website hosted on raspberry pi

I'm trying to host a website on a Raspberry pi4. I'm having some problems displaying the folder.
The code below is what I have so far, but, the following error message appears when I press the link: The requested URL was not found on this server.
<title> Folder </title>
</head>
<body>
<h1>Folder</h1>
<a href ="\home\pi\Documents" > Click to open folder </a>
</body>
</html>```
There are two obvious problems here:
Path separators in UNIX/UNIX-like operating systems (including Linux) and in URLs are /, not \.
URLs need to be provided by an HTTP server (such as Apache HTTPD, Nginx, or Lighttpd). In a traditional configuration (designed to just serve up static files) the root of the website will map on to a specific directory on the file system, and not the root of the file system (which would expose all sorts of private files).
The path you need to ask for needs to treat / as the server's root directory and not the file system's root directory.

Laravel blade template view HTML::style not linking in sub folder

I have:
{{HTML::style('css/bootstrap/bootstrap.min.css')}}
Which in the source code comes out as:
http://www.view.local/laravel/css/bootstrap/bootstrap.min.css
Which is wrong.
It should be:
http://www.view.local/laravel/public/css/bootstrap/bootstrap.min.css
But of course I don't want it to show the laravel part of the source.
The project directory is:
http://www.view.local/laravel
Which is working fine for everything else.
How can I get this to work properly?
This works exactly as expected.
Public folder should be configured as root directory for laravel applications. You should set path_to/laravel/public as directory for your virtual host. That will solve the issue.
Making path_to/laravel as root directory will make your application vulnerable. Always make sure that you give web access only to public directory. If you are hosting on a linux based web server, the content of public folder should go to public_html folder.
Laravel links all the resources file to the public folder so you can use the asset() function in this way:
<link href="{{ asset('style.css') }}" rel="stylesheet" type="text/css">
where style.css must be in public/ folder

when I try to open an HTML file through `http://localhost/xampp/htdocs/index.html` it says unable to connect to localhost

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/???.???

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.

Aptana Studio 3 preview problems with absolute path

I have this structure for my project:
Root Directory
|-css folder
|-style.css
|
|-it folder
|-index.html
If I try to include css file with:
<link href="/css/style.css" rel="stylesheet" type="text/css"/>
from index.html, aptana preview and also internal server can not find style.css.
Why is this?
In my remote server it works perfectly and I do not want to use a relative path.
In terms of the "why", the problem you are having is related to how your development server is setup versus your production server.
Assuming a standard setup, your production server will receive requests for a domain (i.e., http://mysite.com) that is, for lack of a better word, mapped to a folder on your server (i.e, a request to http://mysite.com will be mapped to a folder, /var/www/mysite, on your server).
So, when you link to a style sheet with /css/style.css, your (production) sever immediately goes to the /var/www/mysite folder and starts looking for the css folder, file and so on. No problems with that, as you point out.
Your development machine, however, is serving up pages locally and has a different directory structure for mapping to files and folders.
When I open an HTML page in my Aptana project and hit the preview button, Studio loads http://127.0.0.1:8020/mysite/public/404.html (note how the first folder after the IP and port is mysite). To load the absolutely pathed CSS file, the local server is actually looking for http://127.0.0.1:8020/css/styles.css but it needs to get to http://127.0.0.1:8020/mysite/css/styles.css.
The initial "/" in your link (/css/styles.css) tells the server to go to the root directory of the server and start looking for the folder and files from that point ... but there is no css folder in the local server's root directory. It lives in /mysite/css/styles.css and that's why fskreuz suggests relative paths and using "../css/styles.css" instead.
Personally, I prefer absolute links (but that's just a personal preference and not in any way a challenge to or comment upon fskreuz's response). However, my local development setup is conducive to using them because I setup virtual hosts for the sites I work on. Using Apache, I setup a virtual host for each of my projects. With this, I can load something like http://dev.mysite.com in any browser on my computer and test my site/app in a way that makes it mirror my production setup.