2012-08-13 129 views
1

如何从urls中删除'index.php',如果控制器文件夹中有一些控制器,子文件夹中有一个? 比如我的前端URL看起来是这样的:domain.com/site/contact.html 我想我的后端的网址是这样的:domain.com/system/settings/profile.html,其中系统不控制器,只有控制器文件夹中的子文件夹。 当我输入domain.com/index.php/system/settings/profile.html,一切正常,它只是看起来不正确。 下面是在我的routes.php文件文件:Codeigniter - 子文件夹中的控制器,从url中删除index.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] 

感谢。

回答

0

你可以尝试设置RewriteBaseRewriteBase /RewriteBase /site/

+0

这也不起作用。我会在.htaccess文件中需要某种异常。不管怎么说,还是要谢谢你。 – 2012-08-13 16:50:04

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

要删除URL首先检查了mod_rewrite的index.php Apache中后启用了在.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文件夹中的config.php设置

$config['index_page'] = ''; 
+0

@ thanks Dude ... – KarSho 2013-07-03 06:45:35

0

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

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

你不能说出你的子文件夹中的“系统”,因为在根文件夹中的文件夹“系统”。

相关问题