how to prevent directory access and show forbidden error in php

前端 未结 3 1698
梦谈多话
梦谈多话 2020-12-24 08:31
  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

3条回答
  •  生来不讨喜
    2020-12-24 08:38

    You can simply add the following to your .htaccess

    # Don't listing directory
    Options -Indexes
    ErrorDocument 403 http://www.your-website-home-page.com/
    # Follow symbolic links
    Options +FollowSymLinks
    
    # Default handler
    DirectoryIndex index.php
    

    This will load only the index.php file while file browsing. If no index.php file is found 403 error happens (Access restricted) and it will send the user to home page

提交回复
热议问题