我的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