1

My project structure is:

-application
-lib
-public
-index.php
-.htaccess

.htaccess now is:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

I need to restrict access to all folders exept public and index.php file. How to do it?

I tried to add Deny all to my .htaccess and Allow all into public folder, but my index.php become inaccessable.

ovnia
  • 2,412
  • 4
  • 33
  • 54

1 Answers1

0

Don't use a RewriteRule. Use the following instead:

Order Deny,Allow
Deny from all
Allow from 127.0.0.1

<Files /index.php>
    Order Allow,Deny
    Allow from all
</Files>

<Directory "/public">
    Allow from all
</Directory>
Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Xavjer
  • 8,838
  • 2
  • 22
  • 42
  • See also for example: http://stackoverflow.com/questions/13251500/deny-access-to-all-php-files-except-root-index-php – Stefan May 20 '14 at 16:41
  • Did you write this yourself? – Amal Murali May 20 '14 at 16:42
  • It is adapted from two websites, there are even some sites which can generate this easily – Xavjer May 20 '14 at 16:44
  • @Xavjer but my index.php is an `FrontController`, so all requests should be redirected there. How to save this behavior? – ovnia May 20 '14 at 16:50
  • Okay, that is an other case, check http://premium.wpmudev.org/forums/topic/redirect-all-pages-to-indexphp-except-one-page adapt it to your public folder and it should work – Xavjer May 20 '14 at 17:41