Php 如何使用.htaccess将目录指向加载索引

Php 如何使用.htaccess将目录指向加载索引,php,apache,.htaccess,Php,Apache,.htaccess,我正在尝试为我的网站配置.htaccess 我的网站中有两个文件夹1-app,2-public 我想从公用文件夹加载index.php,并限制对app文件夹的所有直接访问 我正在使用的.htaccess返回结果403禁止,但是如果我在根目录中移动index.php,我只想指出index.php在公共目录中,并将所有请求发送到那里 Options -Indexes <IfModule mod_rewrite.c> RewriteEngine On RewriteBa

我正在尝试为我的网站配置
.htaccess

我的网站中有两个文件夹1-
app
,2-
public

我想从公用文件夹加载
index.php
,并限制对app文件夹的所有直接访问

我正在使用的
.htaccess
返回结果
403禁止
,但是如果我在根目录中移动
index.php
,我只想指出
index.php
公共
目录中,并将所有请求发送到那里

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>
选项-索引
重新启动发动机
基础/公共/
#强制排除尾随斜杠
重写cond%{REQUEST_FILENAME}-D
RewriteCond%{REQUEST_URI}(.*)/$
重写规则^(+)/$$1[R=307,L]
#限制php文件的直接访问
重写cond%{u请求}^.+?\[^?]+\.php[?\]
重写规则\.php$-[F]
#允许直接显示现有的任何文件或目录
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?$1[QSA,L]

我这样解决了这个问题, 对于我管理的
root
目录
.htaccess
,就像下面给出的代码一样,我们的想法是将所有调用重定向到
public
dir

Options -Indexes
<IfModule mod_rewrite.c>
    RewriteEngine on

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

你们能发布你们的目录结构吗?在应用程序文件夹中我有核心部分,在公共部分我有索引和资源,我已经设法避免了这样的情况。在根目录中,我制定了对公共目录的重写规则,在公共目录中,我粘贴了这个htaccess并删除了重写库,它成功了
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>