codeigniter不会重定向网址

时间:2012-04-13 07:02:36

标签: php codeigniter

我做了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]

4 个答案:

答案 0 :(得分:1)

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

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

请注意index.php没有/

答案 1 :(得分:1)

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

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

//这是.htaccess文件只需替换它     RewriteEngine On     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]