使用codeigniter从url中删除控制器名称

时间:2017-08-03 06:57:11

标签: php codeigniter

我想从网址中删除我们的欢迎控制器 如何使用codegniter删除索引

$route['^(:any)(/:any)?$'] = "welcome/$0";

但我的链接是

<?php echo site_url('welcome/about'); ?>
<?php echo site_url('welcome/index'); ?>
<?php echo site_url('welcome/contact'); ?>

当点击此链接时,网址是相同的欢迎/联系人和错误页面,我的$ route仅在点击任意网址localhost/mydomain/index时才有效localhost/mydomain/welcome/contact

2 个答案:

答案 0 :(得分:0)

如果您只想从网址中删除&#39; welcome&#39;

你可以这样做:

$route['(:any)'] = "welcome/$1"

<强>其他:

您可以在config/routes.php中定义自定义路线 - 例如:

$route['about'] = 'name_controller/about';

Then, http://example.com/about
goes to http://example.com/name_controller/about

有关详细信息,请参阅CI论坛中的Hiding the controller’s method name in the URL?

答案 1 :(得分:0)

您可以在config/routes.php

中添加路线

对于Ex:

$route['about'] = 'welcome/about';
$route['index'] = 'welcome/index';
$route['contact'] = 'welcome/contact';

您可以使用Like:

localhost/mydomain/about
localhost/mydomain/index
localhost/mydomain/contact

请设置您的网站网址,如:

<a href="<?= base_url() ?>about">Abouts<a/>
<a href="<?= base_url() ?>index">Index<a/>
<a href="<?= base_url() ?>contact">Contact<a/>
相关问题