URL routing for localized frontend and backend |
Hello,
I would like to ask if anyone has solved a similar problem. I have gone through the discussion forum but no advice has helped me. I have the following problem. We have a website where the frontend is localized: domain.com/en/contact domain.com/de/kontakt domain.com/it/contatto This is fine, it works fine for me. I set it up this way: PHP Code: $routes->group('', ['namespace' => '\App\Controllers\Frontend'], static function ($routes) { We have the controllers divided like this: /app/Controllers/Backend/ /app/Controllers/Frontend/ When I added {locale} to the URL, my backend stopped working. I can't figure it out, can someone help me? PHP Code: $routes->group('', ['namespace' => '\App\Controllers\Backend'], static function ($routes) { The application returns a 404 error because there is no language code in the given URL for the backend. I would need to introduce some kind of exception so that the above rules don't apply to /backend. So that the URLs are localized only when I'm not in the backend. Can someone help me?
{locale} in the route definition matches any URI segment.
(09-08-2022, 05:00 AM)kenjis Wrote: See https://codeigniter4.github.io/CodeIgnit...e-priority I tried, it did not solved my problem. I have temporary solution, I will post it here in a while.
By the way, you are using $routes->add(), but it has security risk, so I recommend not to use.
See https://codeigniter4.github.io/CodeIgnit...http-verbs
Your issue happened to me and was 100% like your issue I solved by this way I tell you 100% use this logic condition URL helper it will 100% work
PHP Code: <?php if (url_is('admin')) { https://codeigniter.com/user_guide/helpe...url#url_to Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
After using {locale} it is normal (for me) to face with this problem (or maybe I'm used to it). You should also use {locale} for the backend part. That's the only solution for me.
(09-08-2022, 07:54 AM)demyr Wrote: After using {locale} it is normal (for me) to face with this problem (or maybe I'm used to it). You should also use {locale} for the backend part. That's the only solution for me. Temporary solved like this (I am sure there is better solution): PHP Code: if ($request->uri->getSegment(1) !== 'backend') { Then continues rules for backend - without locale. It makes no sense to have locale in backend URL. kenjis Wrote:By the way, you are using $routes->add(), but it has security risk, so I recommend not to use. Thank you, I updated it in my config. |
Welcome Guest, Not a member yet? Register Sign In |