Hide open directory - php

I have a website and right now users can just open a directory and see all files in it. How do I disable that?
I was thinking about the php.ini file, or generally any php configuration that might do the trick (it is an Apache server run with PHP).

Disable Indexes option in apache configuration.
Put this either in your httpd.conf or .htaccess in the root of the site.
Options -Indexes
This way, if the folder does not have an index page, the user will get a 403 Forbidden error.

Put a text file named .htaccess to your root-dir of your website or the dir you want to hide with following content:
Options -Indexes

Related

Avoid Directory listing in a shared server

I am using shared server for my website and therefore i dnt have access to my httpd.conf.
my director r getting listed like
when i click on mysite.com/xyz/
all php files are showing.
Please help
in your .htaccess file add
Options -Indexes
To follow up and more thoroughness, you can also use an index file in the directory by creating a blank index.html file.
e.g. index.html
Or you can also specify the exact file and orders you want to be the index in htaccess with
DirectoryIndex index.html index.php
So there you have a few choices. The file will have to exist and it can contain anything or nothing.

change security permission in a website

I have a website that is working properly.I dont know when I do "Domain-name.com/images" It shows me all the images in the images folder present at my site.I dont know why is this.may be this is due to the Directory permissions?But I want to ask know the actual reason behind it
Help will be appreciated.
Note:I am tagging Php and Html because these people might faced this thing while creating website.
This is because there is no index file in the folder, and Apache (assuming Apache) is set to do directory indexes.
Either create an empty index.html or add the following in either apache2.conf (or httpd.conf) or in a htaccess file:
Options -Indexes
You can restrict the folders using .htaccess.
Create .htaccess file in you website root folder and add the following code in it.
RewriteEngine on
RewriteCond $1 !^(css|js|images)
RewriteRule ^(.*)$ index.php/$1 [L]
This is a problem with the configuration of your web server which allows directory listing for your image folder. E.g. on Apache, the most common server software, you would switch it off in the httpd.conf with the directive Options -Indexes in a directory section.
To answer your question: yes. If it's a web accessible directory meaning it resides in the typical webroot folder such as public_html, www, etc and the permissions on the folder are open then anyone can see the contents.

Default file for Apache localhost

I have apache2 installed. When i type http://localhost it goes to a file http://localhost/class/index.php . How do i change it to say http://localhost/index.html or any other page? Which file will I find the setting to do this? Thanks!
Find the DirectoryIndex directive in your Apache configuration file (httpd.conf) or add it to a .htaccess file and change it to look like this if you want to limit your default index file to just index.html:
DirectoryIndex index.html
You can also include more resources and they will be used in the order given, e.g
DirectoryIndex index.html index.php
would display the index.html file first if both index.html and index.php existed.
Don't forget to restart Apache if you made the change to the httpd.conf file.
Look at the mod_dir documentation for more information.
Apache will not trigger HTTP redirections unless you instruct it to do so.
My advice is that you open your favourite text editor and search for the class string in the following locations:
*.conf files inside the Apache installation directory.
.htaccess files inside your HTML directores.
If that fails to find anything, you could also search for header() calls in your *.php code.

setting default page for all folders with no index

is there any way to set a default page for all folders on server that don't have an index file?
Like a general 404 page?
The idea is to prevent browsing through folders with no index file
Can this be achieved with .htaccess or php?
Put
ErrorDocument 404 /path/to/file/that/handles/404/errors.php
in your httpd.conf
However, if you're wanting to prevent folder browsing, this won't help. You'll have to disable folder browsing in the first place:
Options -Indexes

How can I stop users from viewing folders that have no index page but other pages on my web site using PHP or mod rewrite?

I just wanted to know how to stop user from viewing folders without index pages using PHP or mod rewrite?
All of these answers are good but I will rate the one with the most votes.
Configure your web server to not automatically serve directory indexes.
Using Apache, this is done with the -Indexes option:
<Directory /web/docs/spec>
Options -Indexes
</Directory>
You can also put this Options -Indexes directive in an .htaccess file in the specific directory.
You don't need PHP for this. Just put a blank index.html in the directory.
By viewing folders, I assume there is a directory listing that you don't want visible. In that case, in your .htaccess file:
Options -Indexes
This can be done on a per-directory basis. See:
http://httpd.apache.org/docs/1.3/mod/core.html#directory

Categories