【问题标题】:codeigniter wont redirect a urlcodeigniter 不会重定向 url
【发布时间】:2012-04-13 15:15:54
【问题描述】:

我按照 htaccess 中所说的做了:

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

我把上面的,这样我就能做到这一点:

http://localhost/Speakom2/Home/index

代替:

http://localhost/Speakom2/index.php/Home/index

但它不起作用...我收到 404 错误..如何解决这个问题才能正常工作?!?

控制器:

class Home extends CI_Controller {

public function Index() 
{
    $this->load->view('welcome_message');
}

}

htaccess:

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

【问题讨论】:

标签: php codeigniter


【解决方案1】:

当您在本地主机上运行时,您的 Web 根目录为 /localhost/mysite/,但在真实主机中,您的根目录为 /mysite: 所以在本地主机使用:

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

注意没有/的index.php

【讨论】:

  • 很好的答案,很好的解释
【解决方案2】:

确保您的.htaccess 文件位于Speakom2 文件夹(Codeigniter 根目录)中。然后改成这个

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

【讨论】:

    【解决方案3】:
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]   
    

    【讨论】:

      【解决方案4】:

      //这是.htaccess文件,替换它 重写引擎开启 RewriteBase //

      #Removes access to the system folder by users.
      #Additionally this will allow you to create a System.php controller,
      #previously this would not have been possible.
      #'system' can be replaced if you have renamed your system folder.
      RewriteCond %{REQUEST_URI} ^system.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
      
      #When your application folder isn't in the system folder
      #This snippet prevents user access to the application folder
      #Submitted by: Fabdrol
      #Rename 'application' to your applications folder name.
      RewriteCond %{REQUEST_URI} ^application.*
      RewriteRule ^(.*)$ /index.php?/$1 [L]
      
      #Checks to see if the user is attempting to access a valid file,
      #such as an image or css document, if this isn't true it sends the
      #request to index.php
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php?/$1 [L]
      

      【讨论】:

        猜你喜欢
        • 2015-11-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-11-12
        • 2013-04-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多