想要从Codeigniter URL中删除Index.php

时间:2013-06-29 06:50:00

标签: php .htaccess codeigniter

我想从代码点火器URL中删除 index.php ,我创建了 .htaccess 文件,并将其存储在与index.php并行的应用程序文件夹中,并删除< / p>

$config['index_page'] = '';

来自config.php。

.htaccess文件中的代码,无效:

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

项目的网址为:

localhost/WCPM/index.php

注意请不要将此问题标记为重复,因为我已经尝试了很多相同的解决方案,但它们都不适合我,所以最后我问这个这里提出解决方案的问题

5 个答案:

答案 0 :(得分:1)

在Config.php中更改为

$config['index_page'] = '';
$config['base_url'] = 'http://localhost/WCPM/';

并创建 .htaccess 文件,如

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

并将其保存在根文件夹[WCPM]中,即在应用程序文件夹附近。

更多详情请参阅CI手册@ http://ellislab.com/codeigniter/user-guide/general/urls.html

答案 1 :(得分:0)

在apache中启用mod_rewrite模块。

如果这不起作用或已启用mod_rewrite,请尝试此

<IfModule mod_rewrite.c>
RewriteEngine On

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

</IfModule>

答案 2 :(得分:0)

首先,更改setting文件中的config

$config['index_page'] = '';

然后,使用以下代码替换位于项目根文件夹中的.htaccess文件而不是应用程序文件夹中的文件。

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

答案 3 :(得分:0)

答案 4 :(得分:0)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|imgs)
RewriteRule ^(.*)$ index.php/$1 [L]  
RewriteRule ^media/imatges/([0-9]+)/([A-Za-z0-9-]+).jpg?$ imgs/$1  [T=image/jpeg,L]
<Files "index.php">
AcceptPathInfo On
</Files>

这是放在.htaccess文件开头的整个推荐代码

相关问题