How to make domain url lead to index.html? - 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.

Related

Have index.html file but still getting a directory listing

I have an index.html file in my Apache DocumentRoot directory but when I go to my URL, I am still getting a directory listing of my DocumentRoot directory instead of the index.html file being displayed. The apache access_log shows 200's when I reload the page. Any suggestions?
Use
DirectoryIndex index.html
It tells apache what document to show for a directory request.
update
You should specify just the filename that apache will look for in the folder requested.
Not saying this will fix it for you, but for me when first getting started with Apache2 it was file permissions that would get forgotten when moving or writing new file under the web root directory
ls -hal /var/www/host_one/index.html
If above doesn't have read (r) permissions for the same user:group or if the ownership doesn't include the user/group of the web server, then try the following for allowing group reads
# Modify ownership, change 'www_host' to Apache2 group
chown ${USER}:www_host /var/www/host_one/index.html
# give read+write (6) to user and read (4) to group owners
chmod 640 /var/www/host_one/index.html
Try refreshing the website and see if permissions where the issue. Note most web documents only require read permissions and ownership to be correct for browsers to be allowed to pick them up for rendering, on rare occasions you may need executable (1 or x) permissions for server scripts (be cautious of ownership in such cases) and last write permissions (2 or w) should likely never be seen without good reasons on files within your web root.
Second thing to try, use the index.html within your browsers URL bar
# by IP
http://192.168.0.100/index.html
# by domain
http://site-name.local/index.html
If the above loaded your document then, like #Pekka 웃 stated already, you've likely got a server option that's missing or enabling directory listings instead of looking for a index page within that directory. If this is the problem then there's two ways of fixing it that I've tried in the past. One, htaccess configuration to disable directory listing within that sub-directory, two, server vhost configuration to prevent whole site from directory listings. Personally I prefer to use option two and then on directories that should be allowed to be listed place an htaccess config for permissions instead of denials.

Access htaccess of another website

How do I download an htaccess file from another website?
How do I view my own htaccess in my browser?
I have tried to go to www.website.com/.htaccess but no success for example.
I know that there is a command that can be added to the htaccess file to disable viewing but I'm talking about htaccess files that do not include this code.
By default, Apache config has
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ".ht*">
Require all denied
</Files>
So you can't, or you shouldn't be able to. It would be a security problem otherwise.
How do I download an htaccess file from another website?
That's not possible, .htaccess can contain sensitive information, that's why the default configuration prevents access to this file.
How do I view my own htaccess in my browser?
You can modify the server configuration (see how to configure apache to view hidden (.) files?) to unblock access to this file. But if you have access to this configuration, you probably have an access to the file, so you should be able to view it with another tool than your browser.

LAMP - make directory accessible only to certain web pages

I am tinkering around with webpages on a LAMP server running Apache2 and was wondering if it was possible to make a directory accessible only to your web pages and not from outside?
Example scenario:
Directory to protect: dir1 containing images (jpg, png)
My own webpage: mypage.html that calls images from dir1
My website: www.myweb.com that contains both dir1 and mypage.html
Currently, files inside the website can be accessed via www.myweb.com/dir1/somefile.jpg or by calling mypage.html
I would like it to only be accessible by calling mypage.html
I have tried the following:
modifying .htaccess to disallow access of image types
<files "*.jpg">
deny from all
</files>
(doesn't work because mypage.html cannot access it either)
Modify apache2 conf file with:
<Directory /var/www/dir1>
AllowOverride None
<Limit GET POST OPTIONS>
Order deny,allow
Deny from all
</Limit>
</Directory>
(this actually semi-worked as it allowed me to write to directory but not read, maybe this can be modified to allow requests coming from internal web pages to go through?)
I guess to conclude, is there a way to get Apache2 to ONLY accept requests to access a directory if it is of a certain url of your choosing?
Thanks in advance.
So, I've decided that the approaches I've taken so far really don't cut it and found you could actually call a php function where
<img src='somefile.php?query=xxx' alt='pic'>
and where in the somefile.php I have that takes in img file name created from the query above.
echo file_get_contents($imgresource);
By serving the image from a php script and blocking this php script from being called without proper credentials, sessions, cookies and IP blocking, there is some security set.
So I guess it doesn't really answer the question in its entirety of blocking access only to some URLs but it works for the purpose of not being able to be accessed externally since I have buried the directory below (or above?) the web root directory where it can't be called from a url and only from internal script.

How to use root-relative URL's on Apache server without a domain name?

I have a staging server (VPS) that has a dedicated IP address. For example, http://numeric.ip.address/
I can access the the files in the public_html folder by doing the usual tilda thing in the URL - http://numeric.ip.address/~account/
I have a folder I've developed locally that uses root-relative paths to resources, but
when I load the file in the browser, those root-relative URL's jump up in the directory all the way to the root IP address, instead of the public_html folder /~account/.
I realize there are better ways to set up a staging server and I plan to do so in the future, but I'm facing a deadline where it would be really handy to make this work.
I've tried tossing a base href tag in header tags, but that isn't doing the trick.
In Apache, normally you have "VirtualHost" container or .htaccess file. In it, you set your domain and DocumentRoot.
From what you describe, all you need to do is set your DocumenRoot correctly to you root of your site. then in the Browser, you can point to your paths. So if you have folder called "finance" and inside that folder you have document call "report1.pdf", you can put in your browser, example.com/finance/report1.pdf -as long as you have your DocumentRoot and site setup correctly and put the files in correct path, Apache will serve the file.
<VirtualHost 10.1.2.3>
ServerName example.com
ServerAlias www.example.com # not necessary
DocumentRoot /www/docs/host.foo.com
...omitted the <Direcotry> </Directory> stuff
</VirtualHost>

Disable viewing directory tree via url

I bought a domain name and am trying to figure out how to configure it responsibly. I haven't set up an index.html file yet and I've noticed that if I hit my domain, I see my file directory tree and I can dive down to all the files within my browser. Is there a way that I can disable this? I am hosting it on Apache
If you are using IIS.
Right-click on your website, and choose Properties.
Select Home Directory tab.
Uncheck the Directory browsing.
You can try a few things:
create an empty file named index.html and upload it into the public_folder
create an .htaccess file with the following contents: Options -Indexes
If you have some kind of cpanel for your site, look for options to disable directory browsing.
Creating the index.html file is probably the easiest and most consistent way to go.
FYI, my .htaccess info came from techiecorner.com