2011-03-22 49 views
0

我使用codeigniter,當我設置網站時,我在我的.htaccess文件中添加了必要的代碼,以從我的url刪除index.php(默認)。我剛剛從我網站的備份文件中取代了我的public_html文件夾。由於我這樣做,我不能得到主頁上的任何鏈接工作,除非在域名和其他網址之間插入index.php,如http://www.obsia.com/index.php/contact/而不是http://www.obsia.com/contact/,它的工作原理。因此,在應用程序文件夾中的我的配置文件,我改變無法從我的URL在Codeigniter中刪除index.php

$config['index_page'] = ""; 

$config['index_page'] = "index.php"; 

和所有的鏈接似乎現在的工作。但是如何從URL中刪除index.php。

這裏是我的.htaccess代碼如下所示:

RewriteEngine on 
RewriteBase/
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css) 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

任何人都可以點我在正確的方向。它將非常感激。

問候, 摹

回答

3

喲想做的事可以做到這樣什麼:

RewriteEngine on 
RewriteBase/
# Static content. Rewrite to - (don't change) and mark as last rule. 
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L] 

# Do the rewrite. 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

然而,這樣做的稍微好一點的方法是這樣的:

RewriteEngine on 
RewriteBase/
# Only do the rewrite under the condition that the requested URL isn't a (real) file. 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
+0

我都嘗試,它仍然給了我404錯誤,如果我從URL中刪除index.php。我可以刪除整個.htaccess文件,但似乎沒有什麼區別。在我看來,它根本沒有考慮.htaccess文件。不知道爲什麼,什麼是壓倒一切。 – strangeloops 2011-03-23 08:39:52

+0

試試 RewriteRule ^。* $ - [F,L]這是一個簡單的測試,應該在** everything **上顯示403禁止。如果這不起作用,也許你沒有在Apache配置中啓用mod_rewrite。請參閱:http://stackoverflow.com/questions/5390139/htaccess-not-working/5390747#5390747 – nitro2k01 2011-03-23 11:20:34

+0

我沒有嘗試上述測試,它仍然與404時間每次我點擊一個鏈接(當index.php通過主頁從URL中刪除)。這是工作之前我昨天恢復網站文件的備份,當我已經備份工作。我確實可以訪問httpd.conf文件來啓用mod_rewrite。有沒有其他辦法可以做到這一點? – strangeloops 2011-03-23 15:06:08

2

有是如此之多的HT訪問文件...在我的情況下,我正在編輯錯誤的文件...你應該編輯項目內的文件..例如我工作的代碼點火器和項目名稱是噸est,所以裏面的測試文件夾我有一個htaccess文件,並在我的應用程序文件夾,即測試/應用程序有另一個htaccess文件..我編輯應用程序文件夾內的訪問文件,但我不得不編輯測試文件夾中的文件不測試/application/.htaccess ....希望和1個查找這個有用的..因爲我花了半天摸不着頭腦:(

乾杯 KSP