在 CodeIgniter 中删除 index.php 在 Laragon 中不起作用

Removing of index.php in CodeIgniter not working in Laragon

我想在使用 Laragon

时从 CodeIgniter 的 URL 中删除 index.php

我已经在 CodeIgniter 中编辑了 .htaccess 文件并应用了规则;我还在 application/config/config.php.

中将 index_page 变量更改为空字符串

正如预期的那样,它在使用 WampServer/xampserver 的 Web 环境设置中完全正常工作,但在使用 Laragon 时失败。

可能是Laragon环境的问题,不知道怎么解决

如何让它在 Laragon environment 中工作? (在 Wampserver 工作)。

我的 .htaccess 文件包含以下代码:

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

C:\laragon\etc\apache2\sites-enabled 中,您将找到工作目录中的所有 v-hosts laragon。

当您找到 codeigniter 并打开编辑它时,您将看到一个普通的 apache VirtualHost

更改此行:<Directory "C:/workspace/my_project">

至:<Directory "C:/workspace/my_project/index.html">

重命名 laragon .conf 文件并从文件名中删除 auto.

重启一切。

小心打开对v-host。 Laragon 创建了 2 个 v-hosts,其中 1 个是您在设置中定义的扩展名,另一个是 .com 扩展名。

编辑:

<VirtualHost *:80> 
    DocumentRoot "C:/laragon/www/gmap_polygons/application/""
    ServerName gmap_polygons.dev 
    ServerAlias *.gmap_polygons.dev 
    <Directory "C:/workspace/woo-backend-laravel/application/">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

# If you want to use SSL, enable it by going to Menu > Apache > SSL > Enabled

然后我通过在 Laragon 社区获得一些帮助解决了这个问题

修复其实很简单。

Laragon 编译时 httpd.conf 设置为拒绝覆盖文档根目录。

要对此进行编辑,请查看

上的文件
{LARAGON_ROOT}/bin/apache/httpd{other-version-details}/conf/httpd.conf

并将文件第 251 行到第 278 行附近的某处将 AllowOverride 更改为 All 并重新启动您的 Laragon 服务器。

那就解决了

注意:

您必须在 codeIgniter 中进行设置,例如您的 index_page 变量在

中应该为空
application/config/config.php

$config['index_page'] = "";

并且 .htaccess 文件包含以下内容:

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

如果还是不行,把httpd.conf中的所有AllowOverride None都找出来,改成AllowOverride All。如有必要,请重新启动计算机。