的.htaccess只​​允许访问并重定向到根的index.php只为一个目录 [英] .htaccess only allow access and redirect to root index.php for only one directory

查看:460
本文介绍了的.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]

这篇关于的.htaccess只​​允许访问并重定向到根的index.php只为一个目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆