gpt4 book ai didi

php - 如何使用 .htaccess 指向目录以加载索引

转载 作者:行者123 更新时间:2023-12-05 05:24:30 25 4
gpt4 key购买 nike

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

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

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

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

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>

最佳答案

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

Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on

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

为了过滤请求,我曾经将第二个 .htaccess 放到 public 目录

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>

关于php - 如何使用 .htaccess 指向目录以加载索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34329867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com