Codeigniter,路线。保留网址

问题描述 投票:1回答:2

我的网站太旧,无法重新创建。没有资源,但是所有链接看起来像

http://example.com/about.html

http://example.com/contact.html

http://example.com/countryname.html

http://example.com/countryname/cityname.html

主人说:“这是Joomla”,但我想知道为什么链接如此简单,就像是单独的“ .html”文件的数量一样。

我完全不使用Joomla,我更喜欢Codeigniter。但是有什么方法可以使URL保持相同吗?

例如,在我看来

<a href="<?php echo base_url('/welcome/countrieslist/germany');?>" class="menu__link">Germany</a>

http://example.com/welcome/countrieslist/germany

我需要http://example.com/germany.html

谢谢您的帮助。

php codeigniter routes url-routing
2个回答
0
投票

向网址添加标识符,例如:

http://example.com/germany-c.html

基于该c标识符,您可以在知道该URL表示什么的同时路由任何URL。在这种情况下,c代表国家。

然后在config / routes.php中添加路由:

$route['(:any)-c.html'] = 'welcome/countrieslist/(:any)';

0
投票

谢谢Donboo。

过一会儿,我认为最简单的方法是

$route['what-I-would-like-to-have-in-url'] = 'mycontroller/mymethod';

然后我需要重新定义base_url函数,以便将.html添加到所有url。

很奇怪,但是

$config['url_suffix'] = '.html';

不添加任何内容。

© www.soinside.com 2019 - 2024. All rights reserved.