繁体   English   中英

.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

我用thid代码编写了.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 Server左键单击托盘

图标-> Apache-> Apache模块->并找到并单击rewrite_module

首先,确保您的.htaccess文件正在运行(由Apache / PHP加载)

要对此进行测试,请打开您的.htaccess文件,然后输入一些垃圾文本(例如,test ..)并保存该文件。

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

如果收到“内部服务器错误”,则表明您的.htaccess文件正在运行。 否则,如果默认页面正在加载,则意味着您的.htaccess文件未加载。

如果您的.htaccess文件不起作用,则归因于Apache配置问题。

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

  2. 搜索单词“ AllowOverride”。

  3. 从更改所有实例的值

AllowOverride无

允许全部覆盖

  1. 保存Apache配置文件。

  2. 重新启动Apache服务/服务器。

这应该可以解决您的重定向问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM