我需要路由到例如“www.url.com/controller/function”我将代码放在'config.php'中的路由中,但不起作用。我需要加载到同一控制器中的视图,而不在URL中放入'index.php'。有可能吗?
答案 0 :(得分:0)
这是帮助URL从url
中删除index.php您必须使用 .htaccess 文件从网址中删除index.php
希望有所帮助
<强>更新强>
看一下application \ config \ config.php文件,有一个名为'index_page'的变量
看起来应该是这样的
$config['index_page'] = "index.php";
将其更改为
$config['index_page'] = "";
这里是你可以使用的.htaccess文件..
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
以下是一些使用完整链接..您可以按照这些..
remove index.php stackoverflow
remove index.php codeigniter forum
Enable mod rewrite from your server
希望这些能帮到你
答案 1 :(得分:0)
默认情况下,index.php文件将包含在您的网址中:
www.url.com/index.php/controller/function
您可以使用带有一些简单规则的.htaccess文件轻松删除此文件。下面是这样一个文件的示例,使用“否定”方法,除了指定的项目之外,所有内容都被重定向:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
将包含上述代码的.htaccess文件放入您的app根文件夹。