.htaccess Codeigniter将基本url重定向到默认控制器

.htaccess Codeigniter将基本url重定向到默认控制器,.htaccess,codeigniter,redirect,.htaccess,Codeigniter,Redirect,在我的站点中,基本ur是 base_url = 'localhost/cl/' 当他们输入“localhost/cl/”时,我想重定向到“localhost/cl/index.php/welcome”。我使用.htaccess文件重定向,但它不起作用。我怎么能这样做?这是我在.htaccess中使用的 Redirect 301 / http://localhost/cl/index.php/welcome 更新 我找不到使用htaccess解决此问题的任何解决方案。我在默认控制器中放置了一个

在我的站点中,基本ur是

base_url = 'localhost/cl/'
当他们输入“localhost/cl/”时,我想重定向到“localhost/cl/index.php/welcome”。我使用.htaccess文件重定向,但它不起作用。我怎么能这样做?这是我在.htaccess中使用的

Redirect 301 / http://localhost/cl/index.php/welcome
更新 我找不到使用htaccess解决此问题的任何解决方案。我在默认控制器中放置了一个if语句,将我重定向到desire页面

if(current_url() == base_url()) {
    redirect(base_url().'index.php/welcome/');
}

谢谢大家给我宝贵的时间。

routes.php可以处理

链接

按照以下步骤解决您的问题

将此代码添加到.htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|bootstrap|dist|plugins|css|js|images|robots\.txt)
RewriteRule ^(.*)$ index.php?$1 [L]
config.php中

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/ci/';

$config['index_page'] = '';
$route['default_controller'] = 'welcome';// Your controller name as landing page.
routes.php中

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/ci/';

$config['index_page'] = '';
$route['default_controller'] = 'welcome';// Your controller name as landing page.
如果它不工作意味着,您需要在Apache中启用
mod_rewrite


祝您一切顺利。

您在config.php
$config['base\u url']='http://localhost/cl/';是,我在配置中设置了这个。但我想在任何人在浏览器上键入此内容时重定向,您可以使用
config
文件夹中的
'rount.php'
而不使用
htaccess
file@Ayyappaamara我找不到任何方法重定向基本url,当ulr有控制器或方法名时,它可以工作。@aziz您能共享您的config.php和route.php文件吗?然后我可以给你完美的解决方案。没有路由基本url的选项,我想当我有一个控制器或方法时,我可以使用路由重定向或重写url。我按照你的指示更改了我的代码,但它不起作用。它没有重定向,输入'localhost/ci'后,我没有重定向到'localhost/ci/index.php/welcome',为什么
index.php
会出现在url中?您的项目或需求中是否需要
index.php
?是的,兄弟,index.php是必需的,我使用了它,并在我的问题中提到,它不会起作用。它会生成一个很长的url:'(