Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to prevent directory access and show forbidden error in php

Tags:

php

apache

  1. I am new to .htaccess, i want to know how to use .htacces to prevent direct access via url of my folder e.g. localhost/mycart/images/ OR localhost/mycart/css should show forbidden message.

  2. currently i've put index.php in every folder of my website and echo the messages is it good way to do it.

  3. when i access my website like www.mycart/index.php/css or www.mycart/index.php/images it show website without images and css why and how to fix it?

like image 673
user_quest Avatar asked May 27 '12 09:05

user_quest


People also ask

Why do I keep getting 403 Forbidden?

The 403 Forbidden error means that your server is working, but you no longer have permission to view all or some of your site for some reason. The two most likely causes of this error are issues with your WordPress site's file permissions or . htaccess file.


1 Answers

I have used

# disable directory browsing
Options -Indexes

Conversely, to enable directory browsing, use the following directive:

# enable directory browsing
Options +Indexes

Likewise, this rule will prevent the server from listing directory contents:

# prevent folder listing
IndexIgnore *

And, finally, the IndexIgnore directive may be used to prevent the display of select file types:

# prevent display of select file types
IndexIgnore *.wmv *.mp4 *.avi *.etc

Courtesy From: Prevent Unauthorized Directory Browsing from Stupid HTACCESS Tricks.

It also contains many other useful commands to be used in .htaccess for security and performance enhancement.

like image 181
Asif Avatar answered Sep 24 '22 15:09

Asif