douyi3833 2016-11-23 00:01
浏览 56

CodeIgniter | 某些控制器不会加载,具体取决于.htaccess?

I have two controllers inside my CodeIgniter project. - home.php - dashboard.php

For some reason, my htaccess makes dashboard.php unavailable when I change it to this:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /ci_intro/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L] # THIS LINE HERE
</IfModule>

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

However, when I change it to the code below, home.php is unavailable.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /ci_intro/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L] # THIS LINE HERE
</IfModule>

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

I don't understand why, anyone have an idea of why it would do this?

Thanks, Scott

  • 写回答

1条回答 默认 最新

  • douniao8687 2016-11-23 06:03
    关注

    Try these:

     <IfModule mod_rewrite.c>
    
         Options +FollowSymLinks
         RewriteBase /ci_intro
         RewriteEngine On
         RewriteCond %{HTTP_HOST} !^www\.
         RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
         #Send request via index.php
         RewriteCond %{REQUEST_FILENAME} !-f
         RewriteCond %{REQUEST_FILENAME} !-d
         RewriteRule ^(.*)$ index.php?/$1 [L]
    
        </IfModule>
    

    And make controller home.php as class Home extends CI_Controller and Rename it as Home.php Same for dashboard.php

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序