0

我已经安装了 codeigniter,当我访问 localhost/aplication/index.php 时,我想从 url 中删除 index.php。我已经从 httpd.conf 中设置了取消注释 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 时,它会成功。

我怎样才能解决这个问题??

4

3 回答 3

1

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

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

于 2012-09-21T16:55:53.153 回答
0

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

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

您可以将此变量设置为 '' 或者您可以完全注释掉这一行,无论哪种方式,它都是从您的 codeigniter url 中删除 index.php 过程的一部分。

于 2012-09-21T16:50:50.100 回答
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';
于 2012-09-22T10:17:13.653 回答