Search code examples
php.htaccesscodeignitercpanelshared-hosting

How set sub directories/folders in public_html 403 forbidden


I'm using Codeigniter with Hostgator shared hosting.

How to set sub directories/folders in public_html 403 forbidden? but the files in this folders is accessable.

example:

/public_html/this_forlder_forbidden/this-file-not-forbidden.ext

example 1

/public_html/js/jquery.js

/public_html/css/style.css

below is my .htaccess file codes in /public_html/ directory.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
SetEnvIf Origin "http(s)?://(.+\.)?mydomain\.com(:\d{1,5})?$" CORS=$0

Header set Access-Control-Allow-Origin "%{CORS}e" env=CORS
Header merge  Vary "Origin"

Solution

  • In the directories that are off limits to visit from a browser: place a .htaccess file containing:

    order deny,allow
    deny from all
    

    But if possible, move those directories outside the document root

    Addendum I forgot: for Apache 2.4 the syntax is

    Require all denied
    

    instead of the 2 lines for older Apache versions