CodeIgniter Forums
Remove method and ID from URL - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Remove method and ID from URL (/thread-76976.html)



Remove method and ID from URL - eleumas - 07-09-2020

Hi, i have this url:
Code:
https://mydomain.com/article/39/being-part-of-the-riders-growth-is-worth-every-sacrifice

and i would like have:
Code:
https://mydomain.com/being-part-of-the-riders-growth-is-worth-every-sacrifice

I have tried with routes but i can't. Someone can help me please?


This is the route for article page:
Code:
$routes->add('article/(:num)/(:any)', 'Frontend/Main::article/(:any)');

With this i remove the controller from URL:
Code:
$routes->add('(:any)', 'Frontend/Main::$1');

Thanks.


RE: Remove method and ID from URL - jreklund - 07-10-2020

As you no longer have an identifier in your url, you will need to handle all logic in Frontend/Main. That function (main) will need to check if there are an article under that name or not.


RE: Remove method and ID from URL - inumaru - 07-10-2020

I think it is posible to write the route as
PHP Code:
$routes->add('/(:any)''Frontend\Main::$1'); 
And dont forget to edit your main function too.


RE: Remove method and ID from URL - eleumas - 08-17-2020

(07-10-2020, 02:54 AM)jreklund Wrote: As you no longer have an identifier in your url, you will need to handle all logic in Frontend/Main. That function (main) will need to check if there are an article under that name or not.

Sorry for my latest answer.

I have update my project. This is my URL:
Code:
https://domain.com/article/this-is-my-slug

I would like have:
Code:
https://domain.com/this-is-my-slug

How can i do? Thanks.