Codeigniter - 子文件夹中的控制器,从url中删除index.php

时间:2012-08-13 01:56:38

标签: php .htaccess codeigniter pretty-urls

如果我在controllers文件夹中有一些控制器而在子文件夹中有一个控制器,如何从URL中删除'index.php'? 例如,我的前端网址如下所示: domain.com/site/contact.html 我希望我的后端网址如下所示: domain.com/system/settings/profile.html ,其中system不是控制器,只是controllers文件夹中的子文件夹。 当我输入 domain.com/index.php/system/settings/profile.html 时,一切正常,只是看起来不对。 这是我的routes.php文件中的内容:

$route['default_controller'] = "site";
$route['system'] = "system/login";
$route['404_override'] = 'errors/error_404';

这是我的.htaccess文件中的内容:

RewriteEngine on
RewriteCond $1    !^(index\.php|img|css|public|tmp|download|javascript|rte|document|xajax_js|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

感谢。

4 个答案:

答案 0 :(得分:1)

删除index.php

在项目的根文件夹中创建一个.htaccess文件并编写大量代码:

<IfModule mod_rewrite.c>

RewriteEngine On

    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]

</IfModule>

并保存。

从您的URl中删除index.php并享受。 请注意,.htacess不能在本地计算机上运行。

答案 1 :(得分:1)

要从URL中删除index.php首先检查在apache中启用了mod_rewrite,然后将其添加到.htaccess文件中

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
<。>在.htaccess文件中并将.htaccess文件移到index.php位置附近

/var/www/CodeIgniter/index.php
/var/www/CodeIgniter/.htaccess
配置文件夹集

中的config.php中的

$config['index_page'] = '';

答案 2 :(得分:0)

您可以尝试设置RewriteBaseRewriteBase /

之类的RewriteBase /site/

答案 3 :(得分:0)

我的问题是routes.php文件中保留的控制器名称:

$route['system'] = "system/login";

您无法命名子文件夹'system',因为根文件夹中有一个文件夹'system'。