0

我做了 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');
}

}

访问:

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

4 回答 4

1

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

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

注意 index.php 没有/

于 2012-04-13T07:08:02.900 回答
1

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

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
于 2012-04-13T07:12:12.113 回答
0
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]   
于 2012-04-13T07:08:37.473 回答
0

//这是.htaccess文件,只需在RewriteBase上替换它RewriteEngine //

#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]

于 2012-04-13T07:11:06.960 回答