Can I access files from a subdomain into a parent domain? - subdomain

I created a subdomain inside the folder subdomain, when trying to read css from the parent directory (root) it is not working.
Is there some fix to this?

You'd have to specifiy the full path to the resource on the subdomain ( such as: 'http://subdomain.example.com/styles.css') since the root path will only point to the domain the site is hosted on.

Related

How to make domain url lead to index.html?

How can i make that with entering mywebsite.com it leads to mywebsite.com/index.html?
I'm using siteground and I was recommended htacess but I'm really new at web programming, I don't know what that is and I really don't know what to do
In the Root folder of your website (on the server itself) is a file named .htaccess
That file contains information for the server, about which files and folders are accessable from the internet.
.htaccess can only be accessed when you are logged into your server account. It is a textfile in the Root folder of your hosting area.
In the file you can route all incoming traffic to index.php or index.html or whatever you like.
Here is some more info https://httpd.apache.org/docs/current/howto/htaccess.html
You will need to create .htaccess file in the directory of the website.
Inside it, at its very top, you should add:
RewriteEngine On
DirectoryIndex index.html
That will lead anyone to yoursite/index.html.

How can I disable direct access to a folder html page?

Heres the scenario: In the root of the server i have an folder named "data".
In this folder is a file named "random-file.html". Now I want, that you can't see the contents of the folder "data" if you type "domain.com/data/" but you have access to the file "random-file.html" and can it.
Sure you can. You can hide it using .htaccess. I assume you use xampp server. You can see this [1] https://www.opentechguides.com/how-to/article/apache/115/htaccess-file-dir-security.html
If I recall correctly, the most secure practice is to keep sensitive files outside the root of your webserver all together. Create a folder on the VM or server which your app is hosted and have your application read/write/use it from there.
Most serverside frameworks/tools have a "websecrets" type functionality you could use. But this step above is my 'framework agnostic' advice.

While using nodejs, How can I access files outside root directory?

I'm making a nodejs page to show as an management page.
I need to access a directory outside root directory.
But I can't access with relative path.
Directory example is like this.
C:\resultDirectory\projectA
C:\resultDirectory\projectB
C:\reportDirectory\ProjectA
C:\reportDirectory\ProjectC
C:\NodejsRootDIrectory
What I want to do for now is Access a file in subdirectory of "C:\resultDirectory\projectA". But at the end, I need to access them all. So I can't make webpage root to project A's directory.
What I've dont to access was relative path. sample is
$('#report').load("../../../ProjectA/Daily/DailyReport_191001_151843.html");
I've checked number of "../" and tried add and subtract several times.
For now, this is only code relative to access files.
$('#report').load("../../../ProjectA/Daily/DailyReport_191001.html");
When I check chrome's error, there is only 404 error. the browser can't find out the file I want to see.

Photos are not showing up when using No-IP ddns and linux apache

I don't have a static IP address so a person recommended that I use no-ip.com
I did and now my website is accessible from external internet yay
The problem now is that my photos aren't showing, I thought this would have been a simple issue
I'm not sure if I have to do something with Virtual Host or...
My domain name is greenace92.ddns.net
I can access my index.html file, that shows up fine but the photos aren't showing
On my httpd.conf file I have
ServerRoot "/usr/local/apache2"
The html files are in htdocs under apache2
So, on virtual host that httpd-vhosts.conf file I have the following
ServerAdmin "jacobcun#ricekidengineer.com"
DocumentRoot "/usr/local/apache2/"
ServerName "www.greenace92.ddns.net"
*ricekidengineer.com is my other domain with email configured
I didn't change the error logs from stuck "dummy" stuff
So on my html file for image href's I have
http://www.greenace92.ddns.net/htdocs/images/normalbus-icon-on.png
I assume that www.greenace92.ddns.net is /usr/local/apache2
So I'm just continuing the directory location
Is that correct? What is wrong?
Yeah I don't understand, I even tried three different directories for a few photos, trying directly in apache2, then htdocs, then the images folder
What am I not seeing?
You will have to decide what your want as the domain for your site:
www.greenace92.ddns.net is not setup for your web site
greenace92.ddns.net is the domain setup for your web site.
You either have to
configure no-ip.com to point to the domain www.greenace92.ddns.net
(or)
change your apache ServerName directive to
ServerName "greenace92.ddns.net"
and change the image URLs in your HTML pages from something like
http://www.greenace92.ddns.net/htdocs/images/normalbus-icon-on.png
to
http://greenace92.ddns.net/images/normalbus-icon-on.png
Note: With your current configuration, the 2nd URL mentioned above should already work (It worked when I tested!).

Subdomains and Folders

Just started a site and I have an /img directory on the main domain. I would like to set up a subdomain(where the file folder is just another one in the main directory) that is able to use the /img folder but it doesn't work.
The /img and /subdomain folders are on the same level, so to display images in the main domain I type: <img src="img/image.jpg">
and for the /subdomain I type: <img src="../img/image.jpg">
and I get a 404 error for the site: http://subdomain.example.com/img/image.jpg
As you can see, I want it to be linking to http://www.example.com/img/image.jpg
Can anyone tell me how to achieve this? I would prefer not to link images to their internet directory (i.e. http://www...) because I would like to modify the sites on my computer and upload them via ftp.
I'm sure it's just something that I am messing up or don't completely understand. Thanks in advance!
Relative paths are always relative to a URI. If you have a page at http://subdomain.example.com/ containing a link to ../img/image.jpg, the web server translates it into a link to http://subdomain.example.com/../img/image.jpg. Obviously the web server can't serve anything above it's root directory (that's the whole point of having a root).
Your webserver is configured to only serve content in the /subdomain directory, but obviously /img is not inside that directory, and can't thus be served. What you need to do is configure your webserver to look in /img (the directory on your filesystem) instead of /subdomain/img when it gets an request for any content at http://subdomain.example.com/img/
With Apache this can be done with mod_alias.
Summary: Use mod_alias to map requests to http://subdomain.example.com/img/ to the directory /img.