2014-01-31 57 views
0

我正在使用Codeigniter中的一個不使用標準routing.php文件的項目。 它調用了這樣的函數:test.vi/index.php/controller/function。在codeigniter中刪除index.php替代路由

我的目標是從URL與htaccess的重寫刪除的index.php:

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L] 

而且也是這個config.php文件的變化:

$config['index_page'] = ''; 

我的問題是我需要路由所有的控制器/功能在我的route.php中,或者可以在不使用route.php文件的情況下完成?

+0

編輯你的httpd.conf – Zalaboza

回答

3

首先要確保你啓用了mod_rewrite在httpd.conf:

這樣做添加/確保它exsits此行

LoadModule rewrite_module modules/mod_rewrite.so 

然後在你的笨根文件夾中創建的.htaccess(在index.php文件旁邊)而不是應用程序文件夾。

的.htaccess

DirectoryIndex index.php 
RewriteEngine on 
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA] 

笨照顧你所有路線的;所以

controlers/welcome.php method=helloü可以通過

http://localhost/welcome/hello

訪問它不喜歡你需要專門添加的路由laravel; codeigniter自動爲您設置Fitch控制器。除非你有它存儲在不同的位置或子文件夾內,那麼除了設置默認路由之外,你不需要觸摸route.php。

+0

我試過你的.htaccess仍然得到一個404,如果我不添加index.php的URL。 – Edelweiss

+0

您是否啓用了在您的服務器中重寫? – Zalaboza

+0

編輯我的回答:)乾杯 – Zalaboza

0

這裏是我在現場codeigniter網站的.htaccess重定向。第二部分免除某些目錄。

#Redirect non-www to www: 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteCond $1  !^(index\.php|phpinfo\.php|test\.php|example\.php|images|i|css|js|beta|captcha|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
0

這個作品非常適合我......試試看..

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-s 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L] 
+0

使用'RewriteCond $ 1!^(index \ .php | img | css | js | robots \ .txt | favicon \ .ico)'允許您跳過文件/文件夾的重定向。也避免阻止搜索引擎 – Zalaboza

+0

試過它仍然是404.下面的.htaccess相同的任何想法? – Edelweiss

0

試試這個

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /test.v/index.php?/$1 [L] 

我想每個人都忘記上的.htaccess

添加test.vi文件夾名稱