htaccess文件和CodeIgniter路由中的RewriteEngine规则问题


Problems with RewriteEngine rule in .htaccess file and CodeIgniter routes

我想做的是删除CodeIgniter以下文档中的url中的index.php文件:

http://www.codeigniter.com/userguide3/general/urls.html removing-the-index-php-file

我写了。htaccess文件,代码为:

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

但是当我尝试访问url: http://127.0.0.1/my-site/admin时,它被重定向到http://127.0.0.1/dashboard

这是我的base_url配置:

$ config [' base_url '] = ' http://127.0.0.1/my-site ';

这是routes.php文件:

$route['default_controller'] = 'home'; 
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['admin']='admin/index'; 
$route['admin/login']='admin/login';

任何帮助将不胜感激!

试试这个

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

如果您使用的是wamp服务器,请点击左键托盘

icon->Apache->Apache modules->,找到并点击rewrite_module

首先,确保您的。htaccess文件正在工作(由Apache/PHP加载)

要测试这一点,打开你的。htaccess文件,输入一些垃圾文本(例如:测试…)并保存文件。

现在加载应用程序的主页。(如。http://localhost/mywebapp/)

如果你得到一个'内部服务器错误',那么这意味着你的。htaccess文件是工作的。否则,如果默认页面正在加载,则意味着你的。htaccess文件没有加载。

如果你的。htaccess文件不工作,这是由于Apache配置问题。

  1. 打开Apache配置文件(通常是C:'Apache'conf'httpd.conf)

  2. 搜索单词'AllowOverride'

  3. 更改所有实例的值

AllowOverride没有

AllowOverride所有的

这将解决您的重定向问题。