CodeIgniter:删除index.php重定向到错误的文件夹

时间:2014-08-27 11:12:25

标签: .htaccess codeigniter

我尝试了所有关于从网址中删除index.php的解决方案,但我仍然无法使其正常运行。

问题:
网址http://localhost/rc/index.php/person/find显示正确的网页 URL http://localhost/rc/person/find显示WAMP主页(没有任何图像),就像它重定向到根的父文件夹一样。

我的配置:
我创建的.htaccess放在我的根目录(/www/rc/.htaccess)中,其中包含以下代码:

<IfModule mod_rewrite.c>
  # Turn on MOD REWRITE engine
  RewriteEngine On

  #Remove index.php from the URL
  RewriteBase /rc/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]

  #Also tried the following lines without success
  #RewriteRule .* index.php/$0 [PT,L]
  #RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

</IfModule>

<IfModule !mod_rewrite.c>
    # If mod_rewrite is not installed, fire 404 error
    ErrorDocument 404 /index.php
</IfModule>

我还设置了$config['index_page'] = '';(在www / rc / application / config / config.php文件中)。

2 个答案:

答案 0 :(得分:2)

您必须将规则置于 CodeIgniter的主要规则之前。

用这个替换你当前的代码(你的htaccess必须在rc文件夹中)

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /rc/

  RewriteCond %{THE_REQUEST} \s/rc/index\.php/([^\s]+) [NC]
  RewriteRule . %1 [R=301,L]

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

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

答案 1 :(得分:0)

Justin Iurman在第一个答案的评论中给出了答案:

  

你确定mod_rewrite已启用吗?您可以在apache配置中查看它

可以在httpd.conf文件或WAMP托盘图标中启用。

相关问题