Welcome Guest, Not a member yet? Register   Sign In
Remove method and ID from URL
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

(This post was last modified: 08-17-2020, 07:10 AM by eleumas.)

(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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB