在Codeigniter中隐藏默认控制器名称

时间:2012-06-21 13:24:01

标签: php codeigniter routing

当我的网站第一次打开时,它会直接转到此地址:http://www.website.com/tr/main

但我希望我的链接如下:http://www.website.com/ 我无法删除“tr / main”链接。我该如何解决这个问题?

Php代码:

$route['default_controller'] = "main";
$route['404_override'] = '';
$route['(tr|en)/(.+)$'] = '$2';
$route['(tr|en)$'] = $route['default_controller'];

Htaccess代码:

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]  

2 个答案:

答案 0 :(得分:0)

在routes.php文件中写下以下代码: -

$route['default_controller'] = "main";
$route['404_override'] = '';

然后在你的“主”控制器中,即在main.php中使用

function index() 
{
    // write all your code inside this function    
}

答案 1 :(得分:0)

在config.php文件中编写以下代码: -

$config['base_url']='http://Your Path/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['subclass_prefix'] = 'Base';

在routes.php文件中写下以下代码: -

$route['default_controller'] = "home";
$route['404_override'] = '';