Question

Directory structure for my website is like this:

  • www/
    • PSite/
      • inc/
      • public/

enter image description here
The inc(include) directory is for where i will include all the important and secure PHP files where normally users have no access but only php code from the public directory can access into the inc directory.
And in public direcotry i will have all public files and pages.
I have heared that it's a better security system, and i want to do it using .htaccess file.
Assume i have a .htaccess file in the PSite directory how i can redirect request at PSite to /public/index.html so, users will be unable to reach at inc directory? i was trying with this code, but it dosen't works with other files and folders in public directory.

RewriteEngine On
RewriteRule ^$ /public/index.php [L]

Note that i have changed the path: localhost/PSite with psite.dev using httpd.conf and windows host file
HTTPD Conf:

<VirtualHost 127.0.0.1>
   ServerName psite.dev
   DocumentRoot "C:\wamp\www\PSite"
</VirtualHost>


Thanks

Was it helpful?

Solution

Put in the directory to deny access an .htaccess file containing

deny from all

If you have a sub-directory containing public files insert another .htaccess with

allow from all
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top