我的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';
試試這個http://stackoverflow.com/questions/9455757/how-can-i-avoid-index-php-from-url-in-codelgniter/9455829#9455829。 – 2012-03-19 20:55:37