2012-03-19 137 views
0

我的CodeIgnitor安裝在任何URL上返回404,期望基址爲http://x.example.com/test/)。當我試圖訪問的URL,如http://x.example.com/test/foobar/177,我得到以下404:爲什麼CodeIgniter將/index.php/添加到所有URL?

未找到

請求的URL /index.php/foobar/177此服務器上找到。

當我檢查我的Web服務器日誌(這是Webfaction),它只是說:

[週一3月19日12點23分45秒2012] [錯誤] [客戶12.34.56.78]文件不不存在 :/var/www/html/no_app_on_root.htmlindex.php

一個文件路徑已經被串聯起來的index.php的方式是奇怪的,不是嗎?

這裏是我的.htaccess:

Options +FollowSymLinks 

# Set which file that's fetched if only directory is specified 
DirectoryIndex index.php index.html index.htm 

# don't list category structures 
Options -Indexes 

# don't display .htaccess files 
<Files .htaccess> 
order allow,deny 
deny from all 
</Files> 


<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase/

#Removes access to the system folder by users. 
#Additionally this will allow you to create a System.php controller, 
#previously this would not have been possible. 
#‘system’ can be replaced if you have renamed your system folder. 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php/$1 [L] 

#Checks to see if the user is attempting to access a valid file, 
#such as an image or css document, if this isn’t true it sends the 
#request to index.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
#This last condition enables access to the images and css folders, and the robots.txt file 
#Submitted by Michael Radlmaier (mradlmaier) 
RewriteCond $1 !^(index\.php|images|robots\.txt|css) 
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 


<IfModule !mod_rewrite.c> 
# If we don’t have mod_rewrite installed, all 404’s 
# can be sent to index.php, and everything works as normal. 
# Submitted by: ElliotHaughin 

ErrorDocument 404 /index.php 
</IfModule> 

我routes.php文件:

$route['default_controller'] = "home"; 
$route['404_override'] = ''; 

$route['foobar/177'] = "foobar/foobar_177"; 
$route['foobar/:num/add'] = "foobar/add"; 
$route['foobar/:num/review'] = "foobar/review"; 
$route['foobar/:num'] = "foobar"; 

我的config.php(是,該網站是在一個子域的目錄):

$config['base_url'] = 'http://x.example.com/test/'; 

$config['index_page'] = ''; 

$config['uri_protocol'] = 'AUTO'; 
+0

試試這個http://stackoverflow.com/questions/9455757/how-can-i-avoid-index-php-from-url-in-codelgniter/9455829#9455829。 – 2012-03-19 20:55:37

回答

0

您的重寫規則用於隱藏url中的index.php

RewriteRule ^(.*)$ /index.php/$1 [L] 

發送的所有請求/index.php/$1

,而且沒有那些處理程序,需要專門告訴Apache,你不希望某些URL重定向到index.php

+0

對不起,但我不明白你。 – BaUn 2012-03-19 20:55:32

0

默認情況下,index.php文件將被包含在你的URL:

mywebsite.com/index.php/stories 

您可以輕鬆地通過使用.htaccess文件有一些簡單的規則刪除此文件。下面是這樣一個文件的一個例子,使用「負」的方法中,一切都被重定向除指定的項目:

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 
0

在文件:config.php的

編輯該行:

$config['uri_protocol'] = 'AUTO'; 

到:

$config['uri_protocol'] = 'QUERY_STRING'; 

而.htaccess文件應該是這樣的:

RewriteEngine On 
RewriteCond %{REQUEST_URI} ^system.* 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
+0

我已經從docroot移動了系統和應用程序文件夾,這是否會改變任何東西? – BaUn 2012-03-19 20:52:36

+0

我繼續前進,並嘗試了兩次更改。我仍然得到404,但至少沒有在url中插入index.php: 在此服務器上找不到請求的URL/test/foobar/177。 – BaUn 2012-03-19 20:58:02

+0

這意味着在ROOT中找不到.htaccess文件,或者其中的代碼無法運行。確保它。 – 2012-03-19 21:56:34

相關問題