2012-03-19 139 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

相关问题