gpt4 book ai didi

php - Codeigniter - 如何从 url 中删除 index.php?

转载 作者:可可西里 更新时间:2023-11-01 13:11:23 25 4
gpt4 key购买 nike

我的项目结构如下

/system
/applications
/cache
/core
/helpers
/hook
/language
/libraries
/logs
/third_party
/admin-panel
/config
/controllers
welcome.php
dashboard.php
/errors
/models
/views
welcome.php
dashboard.php
/user-panel
/config
/controllers
welcome.php
dashboard.php
/errors
/models
/views
welcome.php
dashboard.php
/admin
index.php
index.php

我的项目文件夹中的 index.php 将用户面板作为我的应用程序文件夹,管理文件夹中的 index.php 将管理面板作为我的应用程序文件夹。

我插入了这一行$route['default_controller'] = "欢迎";$route['欢迎'] = '欢迎';在用户面板和管理面板中的 routes.php 中

我可以使用 http://localhost/myproject 和 http://localhost/myproject/admin

访问我的用户面板和管理面板的欢迎 Controller

但我无法使用 http://localhost/myproject/dashboard 或 http://localhost/myproject/admin/dashboard 访问我的仪表板 Controller

可以使用 http://localhost/myproject/index.php/dashboard 或 http://localhost/myproject/admin/index.php/dashboard访问我的仪表板 Controller

但我不想在我的网址中包含 index.php。我想删除它。我也尝试过在我的管理文件夹中使用 .htaccess。我在这写下一行

RewriteEngine On
RewriteCond $1 !^(index\.php|(.*)\.swf|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

但这对我不起作用。它给出 404 not found CI 错误。我还通过在 httpd.conf 中将 AllowOerride None 更改为 AllowOverride All 来启用 mod_rewrite。请告诉我应该如何删除 index.php 以及我应该将 .htaccess 文件放在项目目录中的什么位置。

最佳答案

如果您的项目根文件夹不是域的根,即您的网站是域 http://localhost/myproject 的子目录,那么您需要在 .htaccess 文件中添加一行 RewriteBase

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

还要确保,你的 config.php 配置为

$config['base_url'] = 'http://localhost/myproject/';
$config['index_page'] = '';

并且在 apache 的配置文件中启用了 mod_rewrite。

关于php - Codeigniter - 如何从 url 中删除 index.php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11947234/

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