【问题标题】:Codeigniter Default Controller 403 Directory access is forbiddenCodeigniter 默认控制器 403 目录访问被禁止
【发布时间】:2021-02-24 14:16:51
【问题描述】:

我在 Mac OS Catalina 上使用 php 5.6.40 和 codeigniter 3.1.9 我的路线:

$route['default_controller'] = "Homepenta";

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteEngine On


<Files .htaccess>
order allow,deny
deny from all
</Files>

<IfModule mod_rewrite.c>
RewriteEngine on
Options All -Indexes
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php -- END cPanel-generated handler, do not edit

在浏览器上

http:\\localhost\mastertransaksi\

显示错误

Directory Access is Forbidden

但是如果

http:\\localhost\mastertransaksi\Homepenta

它的工作

任何人都可以解释如何解决这个问题?谢谢

【问题讨论】:

  • 我假设你的意思是http://localhost/mastertransaksi/ (等等)你的.htaccess 文件在哪里?你的文件结构是什么?
  • .htaccess 在根文件夹,/Applications/xampp/xamppfiles/htdocs/mastertransaksi/.htaccess

标签: php .htaccess codeigniter


【解决方案1】:

您的DirectoryIndex 似乎没有设置,或者设置不正确(默认为index.html)。将以下内容添加到 .htaccess 文件的顶部:

DirectoryIndex index.php

您的 mod_rewrite 指令不会将 /mastertransaksi/ 重写为 /mastertransaksi/index.php,因为这是一个物理目录,而您的规则不包括目录。

403 结果是因为目录索引被禁用并且没有找到DirectoryIndex 文档。

除此之外: 您有多个 RewriteEngine 指令,这些指令是不必要的,应该删除。还有……

<IfModule mod_rewrite.c>
RewriteEngine on
Options All -Indexes
</IfModule>

删除 &lt;IfModule&gt; 包装器和 RewriteEngine On 指令。只需保留Options 指令即可。

【讨论】:

  • 我将 DirectoryIndex index.php 放在顶部并删除了 ,谢谢@MrWhite。它的工作,它节省了我的时间。
猜你喜欢
  • 2014-04-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-08
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
  • 2012-06-02
相关资源
最近更新 更多