简体   繁体   中英

How to point directory to load index with .htaccess

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>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM