CodeIgniter 从 href 中删除 index.php

CodeIgniter remove index.php from href

在 CodeIgniter 应用程序中

这个link有效

<a href="index.php/controller">link</a>

而这个没有

<a href="controller">link</a>

配置有什么问题?必须更改什么才能使 link 在开头没有 "index.php/" 的情况下工作?

没有成功:

1) 添加到 application/routes.php

$route['(:any)'] = 'controller';

2) 添加到 application/.htaccess

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

<Files "index.php">
AcceptPathInfo On
</Files>

3) 在 etc/apache2/httpd.conf

中取消注释
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
LoadModule php5_module libexec/apache2/libphp5.so

在您的 .htaccess 中使用它从 url

中删除 index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php?/[=10=] [PT,L]

你的link应该是

<a href="/controller">link</a>

Config.php应该是

$config['index_page'] = '';

rewrite_module 应该在 apache 中激活

首先你应该空白

$config['index_page'] = '';

在配置中 config.php 然后在你项目主目录下的.htaccess中写入如下代码。

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/ [L,QSA]
</IfModule>