CodeIgniter Forums
User link - route all request that generates 404 - 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: User link - route all request that generates 404 (/thread-73830.html)



User link - route all request that generates 404 - mirel.popescu - 06-10-2019

Hello,

I want to create user profiles with the following link structure: site.tld/username.
The problem is that if I use: $routes->add('(:any)', 'Profile::userbyname/$1') , it will also redirect valid controllers (ex: login, admin etc).

How can I do this redirect correctly?

Thanks!


RE: User link - route all request that generates 404 - Matleyx - 06-10-2019

You have modified the autoload file?
Can you post the psr4 in that file?


RE: User link - route all request that generates 404 - InsiteFX - 06-10-2019

Did you try this?

PHP Code:
$routes->add('profile/(:any)''Profile::userbyname/$1'



RE: User link - route all request that generates 404 - mirel.popescu - 06-15-2019

(06-10-2019, 01:38 AM)Matleyx Wrote: You have modified the autoload file?
Can you post the psr4 in that file?

No, I didn't. I don't know what "psr4" is.

The code:

$routes->add('profile/(:any)''Profile::userbyname/$1')

works , but then the link will be "site.tld/profile/username", not site.tld/username Smile. Am I missing something?

Thanks!


RE: User link - route all request that generates 404 - InsiteFX - 06-16-2019

You can try this not sure if it will work, it's for CI 3.

HOW TO REMOVE CONTROLLER NAME FROM THE URL IN CODEIGNITER