在 Codeigniter 中,如何使控制器运行 index() 而不必在 url 中写入 /index



我正在设置我的第一个个人代码点火器项目,我的.htaccess文件是这样的:

            <IfModule mod_rewrite.c>
            # Turn on URL rewriting
            RewriteEngine On
            # If your website begins from a folder e.g localhost/my_project then 
            # you have to change it to: RewriteBase /my_project/
            # If your site begins from the root e.g. example.local/ then
            # let it as it is
            RewriteBase /madrigal/
            # Protect application and system files from being viewed when the index.php is missing
            RewriteCond $1 ^(application|system|private|logs)
            # Rewrite to index.php/access_denied/URL
            RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
            # Allow these directories and files to be displayed directly:
            RewriteCond $1 ^(index.php|robots.txt|favicon.ico|public|assets|css|js|images)
            # No rewriting
            RewriteRule ^(.*)$ - [PT,L]
            # Rewrite to index.php/URL
            RewriteRule ^(.*)$ index.php/$1 [PT,L]
            </IfModule>

我已经将我的config.php文件设置为$config['index_page'] = '';和$config['uri_protocol'] = 'REQUEST_URI';但是当我转到我的控制器/admin/时,除非我在URL末尾输入"/index",否则索引不会运行。我的htaccess文件不允许这样做吗?

感谢您的任何帮助

您可以查看以下链接...

http://ellislab.com/codeigniter/user-guide/general/urls.html

无法从代码点火器 URL 中删除索引.php

您可以使用具有一些简单规则的 .htaccess 文件轻松删除此索引.php。

RewriteEngine on
RewriteCond $1 !^(index.php|images|robots.txt|css|img|js)
RewriteRule ^(.*)$ /index.php/$1 [L]

在上面的示例中,除索引.php、图像和漫游器之外的任何 HTTP 请求.txt都将被视为对 index.php 文件的请求。您可以在此处阅读文档

$config['index_page']是 URI 中要调用的默认页面的配置,而不是用于删除索引的配置.php

相关内容

最新更新