【发布时间】:2016-03-23 15:25:30
【问题描述】:
我正在尝试为我的网站配置.htaccess。
我的网站中有两个文件夹 1 - app , 2 - public。
我想从公共文件夹加载index.php 并限制所有对应用程序文件夹的直接访问
我正在使用的.htaccess 返回结果403 Forbidden,但是如果我将index.php 移动到根目录中它正在工作,我只想指出index.php 在public 目录中并将所有请求发送到那里.
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>
【问题讨论】:
-
你能发布你的目录结构吗?
-
在应用程序文件夹中我有核心端,而在公共端我有索引和资源,我设法避免这样。在根目录中我为公共目录制定了重写规则,在公共目录中我粘贴了这个 htaccess 并删除了重写基础,它起作用了