无法使用.htaccess删除index.php

时间:2012-09-21 16:34:26

标签: .htaccess codeigniter

我已经安装了codeigniter,我想在访问localhost / aplication / index.php时从url中删除index.php。我已经从httpd.conf设置了uncomment mod_rewrite.so这是我的.htaccess文件:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
当我从localhost / aplication / index.php / data / users / 12访问url但没有使用此url localhost / aplication / data / users / 12时,它取得了成功。

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

尝试按照此页面关于codeignitor pretty urls。你的规则看起来是正确的,但我对正则表达式很糟糕。

要研究的一些事情是使用phpinfo();检查mod_rewrite是否可用。此链接中的第三步也讨论了使用a2enmod启用mod_rewrite。并确保重新启动Apache。

答案 1 :(得分:0)

检查你的配置文件应该有一行说:

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

您可以将此变量设置为'',也可以将此行完全注释掉,无论哪种方式都是从您的codeigniter网址中删除index.php的过程。

答案 2 :(得分:0)

这是删除index.php的方法:

根文件夹中的htaccess文件:

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

用于管理一些静态页面,例如:example.com/about,example.com/contact,example.com/terms等

配置路由文件并编辑:

//the controller that will be when it is exampl.com
$route['default_controller'] = 'YOUR_MAIN_CONTROLLER_NAME_HERE';
//I creted this for pages that are created dynamically or for displaying error when I want
$route['404_override'] = 'friendlyPages';
相关问题