2012-08-13 128 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"; 

你不能說出你的子文件夾中的「系統」,因爲在根文件夾中的文件夾「系統」。

相關問題