Prevent auto loading index.html from a folder - html

In my /subwebpage/ folder I do contain an index.html file.
When im visiting my website like this: www.website.com/subwebpage
the index.html file is loading automatically. Even the URL don't display www.website.com/subwebpage/index.html
I would like to prevent the auto loading of the index.html file. This means, the index.html should only load, if the client is the URL: www.website.com/subwebpage/index.html
What do I have put into my .htaccess to do this?
I tried with:
# Deny access to everything by default
Order Deny,Allow
deny from all
But it didn't help.

You need to change the DirectoryIndex property in the .htaccess
This property tells the server which filename.filetype combination serves as the default file to be shown when none is provided. It can also accept multiple values separated by whitespace for fallback purporses i.e. if the first one is not found, check the second one etc.
The default property is:
DirectoryIndex index.html
To prevent your server from showing index.html by default, just change the index.html value of the DirectoryIndex property to something that does not exist, for example:
DirectoryIndex filethatdoesnotexist.html
For reference of what I mentioned, this this property can have multiple values separated by whitespace like this:
DirectoryIndex index.html default.html first.html
This means that if the server doesn't find the index.html it looks for default.html and if it doesn't find it either it looks for first.html etc.

Related

Why can't I use file:// in html a tag with href attribute?

I am trying to redirect to a page which lists files using file protocol in HTML <a> tag using href attribute as follow:
Files
The reason I am doing this is to list all the files in my apache document root, as simply going to /will open index.html, which I would not like to disturb (this behaviour is useful to me) and I cannot use server-side scripting like PHP.
You have to configure apache to list the file instead of serving the index.html file.
You can configure this only in certain path
<Directory /var/www/html>
Options +Indexes
</Directory>
but still this will cause the problem of not serving the index.html file (if it's not present).
So you have to decide if you want your server to serve the index file or show the list....

How to add a html header to all html pages of a folder automatically with htaccess?

I tried this
Options +Indexes
IndexOptions FancyIndexing VersionSort NameWidth=* HTMLTable Charset=UTF-8
HeaderName /header.html
ReadmeName /footer.html
IndexIgnore header.html footer.html .htaccess
How To Include a PHP File Site-wide Using .HTACCESS or other methods
Apply .htaccess HeaderName to all lower levels?
How To Include a PHP File Site-wide Using .HTACCESS or other methods
It just simply does not do anything. I also followed an old guide to enable Layout Header (something with mod_layout in apache) but it seems it's too old.
The best i managed to do is to show the content of my "header.html" into the directory (which is listed with Option +Indexes)
I am doing all of this in a specific folder .htaccess, not in the root .htaccess
It looks like this :
Options +Indexes
IndexOptions IgnoreCase FancyIndexing FoldersFirst NameWidth=* DescriptionWidth=* SuppressHTMLPreamble
HeaderName header.html
Please, help
I think you're confusing HTTP Headers with a HTML "Header" (meaning the top of the page)
A HTTP header is used to define things like the encoding, content type (eg JSON/XML), not to add HTML to the top of another HTML page.
If you want to add HTML to the top of each page, .htaccess isn't the place to do this - you need to use some kind of scripting/programming language (eg ASP/PHP) to include the files.
Note that none of the three SO questions you link do what you want either:
How To Include a PHP File Site-wide Using .HTACCESS or other methods and How To Include a PHP File Site-wide Using .HTACCESS or other methods both use PHP to include the files (and just use htaccess to tell PHP where to find the files).
Apply .htaccess HeaderName to all lower levels? as you discovered, adds the header to the Apache directory listing page only, not to every page on your site.
If someone has the same problem, when you write the full path, /www/pages/header.html is not enough, you must write /home/User/www/pages/header.html (if you're on linux or C://etc... on windows)
Why? because it is shown on several folders (recursively), so the path changes depending on the directory you're in

how to display first page in localhost?

I am using Xamp to create a website, I am having a folder named HTML which has a page called Cart.html, the folder HTML is found in htdocs and I want Cart.html to appear as soon as localhost is being input in the browser. That is when I input http:// localhost/, the Cart.html page should appear. I am unable to do, can u suggest me how to do it.
Simple HTACCESS rule:
Redirect 301 index.html Cart.html
Assuming they are in the same folder, otherwise replace with whatever needed
Rename the cart.html to index.html & put it in htdocs as 'htdocs/index.html'
You can create a .htaccess file with the following contents. The only problem here is that any sub folder will look for "Cart.html" as its default page
DirectoryIndex Cart.html
If you do not need the index.html file at all, I recommend deleting it and putting this DirectoryIndex instead
DirectoryIndex index.html Cart.html
This will cause all folders to look for "index.html" first and if it doesn't exist it will use "Cart.html"

What is the simplest way to make a specific page the default page in an html directory?

My html folder contains many html files automatically generated, linked and named by a program. Example: AbcXyzPage1.html, AbcXyzPage2.html, ..., AbcXyzPage100.html, etc.
What is the simplest way to make a particular html file (AbcXyzPage1.html), the equivalent of default.html? So that a user just need to type http://mysite.com/myfolder/ and has that particular page loaded.
Renaming that starting page is NOT an option because all other pages in the folder link to it.
I don't want to use the meta refresh tag.
Add a file named .htaccess to myfolder/ with the following content:
DirectoryIndex AbcXyzPage1.html
If server is Linux, you can link (actually soft link is OK, too).
ln AbcXyzPage1.html index.html
Now you have created index.html - the standard default. Any changes to AbcXyzPage1 will always be "seen" in index.html (since they are the same file).

web folder will not default to index.html

I have a folder on a hosted web server that has an index.html file within it, when I type the URL into the browser along with the index.html the page appears fine like this:
http://www.mywebsite.com/subfolder/index.html
however when I type the URL below the page displays but not properly:
http://www.mywebsite.com/subfolder
If I type the second URL without the index.html should the browser not default to the index page?
Any help would be awesome.
It must be taking index.html by default.
As .htaccess file is defined index.html as the default file.
I checked both the links and both have given the same output.
Can you please check again?