2014-01-05 65 views
0

我是CodeIgniter的新手,我试图弄清楚为什么我在codeigniter网站和SO这里都看到的标准方法不适用于我从我的项目中的url中摆脱index.php。无法摆脱CodeIgniter中的url index.php

我运行CentOS的,和路径,以我的项目是这样的: 的/ var/www/html等/ myproject的

我已经确定mod_rewrite已在httpd.conf由经检查的phpinfo启用()

我.htacess文件看起来像这样:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase /myproject/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.php [L] 
</IfModule> 

我的config.php文件看起来像这样(我自己也尝试PATH_INFO和REQUEST_URI为uri_protocol):

$config['base_url'] = 'http://localhost/myproject/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'AUTO'; 

我的routes.php文件是这样的:

$route['default_controller'] = "site"; 
$route['404_override'] = ''; 
$route['site/price/(.*)'] = "site/price/$1"; 

为现场控制器的价格走势的签名是这样的:

public function price($a, $b, $c) { 
    //code 
} 

当我去

http://localhost/myproject/index.php/site/price/32137/2/1 

的价格功能已成功达成,但是当我尝试

http://localhost/myproject/site/price/32137/2/1 

我得到一个错误页面,指出

The requested URL /myproject/site/price/32137/2/1 was not found on this server. 

我缺少的东西? 在此先感谢

编辑: 如果有任何帮助,我可以到我的项目的网站/索引方法只有url:localhost/myproject但其他任何操作都不可访问。

+0

重复。 [http://stackoverflow.com/questions/5155333/remove-index-php-from-url-codeigniter-2](http://stackoverflow.com/questions/5155333/remove-index-php-from-url- codeigniter-2) –

+0

它不是重复的。它是相似的,但没有任何线程为我工作。 – user3163245

回答

0

使用完全相同的.htaccess mod_rewrite的配置,每次提供in the docs for Codeigniter

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

为我工作。

+0

我最初尝试过,并且现在再次确保我没有遗漏任何东西。它仍然没有工作。我在最后一行尝试了/index.php和/myproject/index.php – user3163245

+0

嗯,这是一个奇怪的。今天晚上这件事会让我保持沉默。多年来一直在玩CI,从来没有尝试过把它放在这样的subdir中。这里有人试图做同样的事情,让我知道它是否有帮助:http://ellislab.com/forums/viewthread/237589/#1058216 – Zarathuztra

0
RewriteEngine On 
RewriteBase /myproject/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php/$1 [L] 
+0

没有骰子。我之前也试过这个块。 – user3163245

0

有2份从URL中除去的index.php:

1)给htaccess来周围的index.php路线。事情是这样的:

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L] 

2)编辑系统/ CMS /配置/ config.php文件配置文件,并从更新此设置:

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

$config['index_page'] = ''; 

这里的一个样品 。htaccess文件我用:

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks -Indexes 
    RewriteEngine On 

    # Keep people out of codeigniter directory and Mercurial data 
    RedirectMatch 403 ^/(/codeigniter|\.git|\.hg).*$ 

    #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} ^codeigniter.* 
    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 
    RewriteRule ^(.*)$ index.php?/$1 [L] 
</IfModule> 

<IfModule !mod_rewrite.c> 
    ErrorDocument 404 public/index.php 
</IfModule> 
+0

正如我在原帖中所说的,我确实已将config.php中的$ config ['index_page'] var更改为一个空字符串,并且从我的.htaccess文件发布的内容与您发布的内容看起来不一样以有意义的方式。无论如何,我尝试过,但它不起作用 – user3163245

0

这个怎么样

.htaccess

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L]