3

I am trying to configure .htaccess for my web site.

there are two folders in my web site 1 - app , 2 - public.

i want to load index.php from public folder and restrict all direct access to app folder

the .htaccess i am using returns result 403 Forbidden, but if i move index.php in root directory it is working, i just want to point that index.php is in public directory and send all requests there.

Options -Indexes

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /public/

    # Force to exclude the trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.*)/$
    RewriteRule ^(.+)/$ $1 [R=307,L]

    # Restrict php files direct access
    RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ]
    RewriteRule \.php$ - [F]

    # Allow any files or directories that exist to be displayed directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?$1 [QSA,L]

</IfModule>
Mikheil Janiashvili
  • 497
  • 1
  • 6
  • 18
  • can you post your directory structure? – jameshwart lopez Dec 17 '15 at 10:19
  • in app folder i have core side and in public side i have index and resources, i have managed to avoid it like this. in root i made Rewrite rule to public directory and in public directory i pasted this htaccess and removed rewrite base, it worked – Mikheil Janiashvili Dec 17 '15 at 11:16

1 Answers1

2

Well i solved this problem like this, for root directory i managed .htaccess like the code given down, the idea is to redirect all calls to public dir.

Options -Indexes
<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteRule ^$   public/   [L]
    RewriteRule (.*) public/$1 [L]
</IfModule>

And for filtering requests i used to put second .htaccess to public dir

Options -Indexes

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /

    # Force to exclude the trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.*)/$
    RewriteRule ^(.+)/$ $1 [R=307,L]

    # Restrict php files direct access
    RewriteCond %{THE_REQUEST} ^.+?\ [^?]+\.php[?\ ]
    RewriteRule \.php$ - [F]

    # Allow any files or directories that exist to be displayed directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?$1 [QSA,L]

</IfModule>
Mikheil Janiashvili
  • 497
  • 1
  • 6
  • 18