Page 1 of 1
stop accessing folder through url
Posted: Tue May 24, 2011 2:54 pm
by bluestar
hii all....im making awebsite in php-mysql....my root folder name is newproject1 and it is in htdoc folder, folder newproject1 contains files and folder one of the folder is style and another is image.....the url when i run a website is
http://localhost/newproject1/filename.php ...but if i chage it to
http://localhost/newproject1/style or
http://localhost/newproject1/image .....it shows all files and folder within these two folder and access them....so how to stop these..
Re: stop accessing folder through url
Posted: Wed May 25, 2011 2:17 pm
by flying_circus
You can put an index.php file in those directories which is either blank, or has a redirect to your homepage. You can also place those files below the document and use a PHP to stream them on demand, but this is not typical for public images and styles.
Re: stop accessing folder through url
Posted: Thu Jun 02, 2011 2:23 am
by twinedev
Another method is drop an .htaccess file in each directory, that just has the following two lines
[text]Options -Indexes
ErrorDocument 403
http://www.yoursitedomain.com/[/text]
The first line says not to display directory index (most hosts let you override this value)
The second line says that when someone gets a 403 error (what you get when get from the above), take them to the specified URL
Note the following about the URL: If you give the full URL (as I gave above), your browser will actually redirect to that URL. If you give just a relative path like the example below, your browser will still show the URL the person browsed to, but display the page listed below:
[text]Options -Indexes
ErrorDocument 403 /[/text]
Nice part of this method over dropping in a index file in each directory is it takes care of the directory you put it in, and any subdirectories in them. And if you don't don't have a need for directory listing at all on the site, put the .htaccess file in the root of the site and it will take care of it all!
-Greg
Re: stop accessing folder through url
Posted: Thu Jun 02, 2011 6:18 am
by social_experiment
twinedev wrote:Another method is drop an .htaccess file in each directory
Wouldn't one .htaccess file in the root folder also suffice? I have only 1 .htaccess folder with the following inside it and it also prohibits directory browsing.
[text]
IndexIgnore *
Options -Indexes
[/text]
Re: stop accessing folder through url
Posted: Thu Jun 02, 2011 3:58 pm
by flying_circus
Awesome, I'm glad you guys posted! I knew it was possible to accomplish the same goal with .htaccess but I wasn't confident enough to include it as a solution. I got to learn something new too

Re: stop accessing folder through url
Posted: Thu Jun 02, 2011 4:28 pm
by twinedev
social_experiment wrote:Wouldn't one .htaccess file in the root folder also suffice?
Yes, that was at the end of my post:
twinedev wrote:And if you don't don't have a need for directory listing at all on the site, put the .htaccess file in the root of the site and it will take care of it all!
Re: stop accessing folder through url
Posted: Tue Jun 07, 2011 5:00 am
by social_experiment
Missed that on the first read through
