Directory listing outside index.html - apache

I have a static website on an Apache server. I have an folder (who's name I don't give out to anyone else) that I don't want anyone to randomly stumble upon. Is there any way to have directory listing under a different page?
To clarify, I have directory listing turned off at the root folder of example.com. In the subfolder that correspondes to example.com/folder1/, I have another .htaccess that allows directory listing. However, I don't want someone who types in example.com/folder1/index.html or the equivalent to see the directory listing. I want them to have to go to example.com/folder1/otherindex.html to see the listing.
Is this possible with Apache?

Should be
DirectoryIndex filename
in your .htaccess

Related

How can I fix my homepage showing a 403 error?

I keep getting a 403 error on my homepage, despite having all my permissions set to allow public to read. I'm not using any plugins, I'm not using Wordpress, and though my site is routed through Cloudflare it goes through to my hosting provider's 403 page (I haven't created my own). I've tried 755 and 644 and I keep getting the same thing. How can I fix this?
(The website is alexbelman.com)
There are several possible reasons depending on your hosting environment and a bit more detailed info from you about your hosting setup would help. For example - is your site on a server running Linux? cPanel?
But maybe this info can help you in the meantime:
If you're sure you have the correct permissions on folders (in most cases your public_html folder should be 750, all folders within the public_html folder in most cases should be 755, and files should be 644) then probably the first two things I would check would be:
Make sure you have an index file in your public_html folder - some examples would be index.html , index.htm , index.php , or on some hosts a default.html is used. If there is no index file in the folder that serves your site, server security configs will often present a 403 while protecting the sensitive contents of your hosting account from being viewed.
If you're sure you have an index file in your public facing folder, then check the contents of the .htaccess file in your public_html folder, since an errant rule or line of code in your htaccess is a common cause for a 403
If you can post the contents of your .htaccess file here someone here or possibly myself can spot anything that shouldn't be there or is incorrect.
Also, since you're using CloudFlare you should take a look at their Quick Fix suggestions here - https://community.cloudflare.com/t/community-tip-fixing-error-403-forbidden/53308

Htaccess redirect the file accessing from one folder to another folder

I have pointed out the robots.txt file in the web folder but with some technical or cache issues, it will not be reflected. so we need to point it out in a different location.
For example
/var/www/html/web/robots.txt
/var/www/html/web/sites/robots.txt
But we should point to the Same URL like this "www.example.com/robots.txt"

Htaccess: redirect to first or only file at directory

I have a website with a structure created by users depending content. That structure is something like this:
www.domain.com/
www.domain.com/vehicles/
www.domain.com/vehicles/vehicles.html
www.domain.com/vehicles/cars/
www.domain.com/vehicles/cars/cars_x.html
www.domain.com/vehicles/bikes/
www.domain.com/vehicles/bikes/bikes_new.html
www.domain.com/vehicles/bus/
www.domain.com/vehicles/bus/bus_big.html
Site is working properly, well seo indexed but sometimes, users or visitors write down wrong addresses like www.domain.com/vehicles/cars or www.domain.com/vehicles/cars/ and that returns a 404 page not found or 403 directory listing forbidden.
Its possible (with htaccess) to tell apache to get the first or only html file on directory if directory exists by default? in pseudocode
if www.domain.com/vehicles/cars is directory
and www.domain.com/vehicles/cars has not default page (index.html/index.php)
get 1st/only .html file at directory for serving it.
bts, its not possible to create or add an index.html/index.php in every directory due its dinamically created by editors and they decide the file names.
Thanks!

Why do I have .htaccess files in multiple directories?

I'm looking through my server because I want to restrict access to some specific folders and i've noticed I have several .htaccess files. One is in the root, the directory before public_html, is that the root, or is public_html the root? And that file enables php5 as default. I then have a htaccess doing some url re-writing in the public_html folder, then I have another one in the wordpress directory.
Is there a need for them to be spread out?
Do I have one htaccess for each folder I want affected or does the htaccess affect a folder plus all of the sub directories?
Thanks
Edit: Also have another htaccess in my wordpress theme folder?
Apache has two ways of storing configuration options:
The central configuration (the .conf files) - when you change these, you need to restart the server.
.htaccess files whose settings apply only to its directory, and all child directories. Changing these does not require a server restart
If you're on a dedicated server, you could theoretically migrate all .htaccess files into the central configuration, but WordPress will write into a .htaccess file when updating its permalink structure, so you'll always have at least that.
In my experience, keeping individual .htaccess files is relatively practical in everyday maintenance work as long as they're not too many. I would leave things as they are.

How Come Everybody Can See My Private Files?

Sorry for the newbie question...
When I go to http://www.plans4boats.com/scripts/youtubeplayer/ in Google Chrome, I can see a full listing of the files there. What should I do if I don't want any old hacker to just come in and view/copy my source codes? Does it have something to do with htaccess?
I discovered that putting a blank index.html file in the folder helps for THAT folder, but it still leaves all subfolders vulnerable.
What should I google for more information on how to set up my server to prevent this?
Just set Options -Indexes for that particular directories either in an .htaccess file or a <Directory> or <Location> container.
What you need to do is turn of Directory Listing for your specific server. I don't know what server you're using so I can't walk you through it, but just google your server name and how to disable directory listing.
I created a file called .htaccess and put the following contents:
IndexIgnore /