的.htaccess只​​允许访问并重定向到根的index.php只为一个目录

问题描述:

我得到一些麻烦与htaccess的在我的新的PHP项目。所以我想问在这里,希望有人可以帮助我走出我找不到任何解决方案。

I'm getting some troubles with htaccess in my new php project . I couldn't find any solutions so I ask here , hope someone will help me out.

1。我需要什么:

在根,指向现有的文件和文件夹的网址不能访问,除/公共/及其所有文件夹和文件(只/公共/被允许访问)。网址指向的文件和文件夹,这是不existings将被重定向到根的index.php 。 /公共/重定向到根的index.php 太,文件夹和文件里面都没有(直接访问)。

On root , urls pointing to existing files and folders are not accessible , except /Public/ and all its folders and files ( only /Public/ is allowed to access ) . Urls pointing to files and folders which are not existings will be redirected to root index.php. /Public/ is redirected to root index.php too , folders and files inside it are not ( direct access ).

2。我曾尝试和不工作:

2 . What I have tried and are not working :

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_URI} !^/Public
 RewriteCond %{REQUEST_FILENAME} !^index\.php$
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>
------------------------------------
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_URI} !^/Public
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>
------------------------------------
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 RewriteRule ^index\.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} -f
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule . - [F,L,NC]
 RewriteBase /Public/
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L,QSA]
</IfModule>

感谢您提前:)

试试这个code根的.htaccess:

Try this code in root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^public /index.php [L,NC]