1

I have a too old website to recreate. Do not have sources, but all the links looks like

http://example.com/about.html

http://example.com/contact.html

http://example.com/countryname.html

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

Well the owner says: "This is Joomla", but I wonder why the links are so simple, just like if it was numbers of separate '.html' files.

I don`t use Joomla at all and I prefer the Codeigniter. But is there any way to keep the URLS the same?

For example, in my view

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

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

I would need to have http://example.com/germany.html

Thank you for any help.

Vadym K.
  • 21
  • 3

3 Answers3

0

Add an identifier to the url, like:

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

Based on that c identifier you can route any url while knowing what that URL represents. In this case, c represents country.

Then add the route in config/routes.php:

$route['(:any)-c.html'] = 'welcome/countrieslist/(:any)';
Donboo
  • 1
  • 2
  • @Vadym K. The way you're proposing it's hardcoded. Not realiable for many URLs or another people. Add .html in your route to use the suffix. – Donboo Apr 29 '20 at 10:39
0

Thank you Donboo.

After a while I think the most simple way is

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

Then I need to redefine base_url function in order to add .html to all the urls.

Strange, but

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

does not add anything.

Vadym K.
  • 21
  • 3
0

The easiest way is to add a prefix to all your Url's provided you have already deleted the /index.php from the framework url CodeIgniter removing index.php from url

`$config['url_suffix'] = '.html'; //Config.php`

//Routes.php

`$route['about'] = 'Controller/function';// example`

`$route['germany'] = 'welcome/countrieslist/germany';`

Then append this to your link in the view

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

Routes can equaly be extended with many parameters. Just take a look at the framework official manual under the topic

Bristol
  • 82
  • 5