![]() |
403 in Controller Subdirectory access - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: 403 in Controller Subdirectory access (/showthread.php?tid=76817) |
403 in Controller Subdirectory access - inumaru - 06-23-2020 This is some of my syntax in Routes file: PHP Code: $routes->add("admin", "Admin/Login::index"); And my folder structure for Controller is like : ![]() Both this link is fine when I access it: Code: http://mydevsite.vhost/admin/home But this link: Code: http://mydevsite.vhost/admin Got a 403 forbidden, is this normal? how can I redirect user who access that link to somewhere else? RE: 403 in Controller Subdirectory access - InsiteFX - 06-24-2020 You also need to pass the sub-folder name. Code: http://mydevsite.vhost/admin/admin/home You need also to pass along the sub-folder name in the uri. RE: 403 in Controller Subdirectory access - MatheusCastro - 06-24-2020 In this type of structure I usually use something like this: Taking advantage of the default controller As Home and the default method index. Code: - Controllers In routes: PHP Code: $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function($routes) So your routes would look Code: http://mydevsite.vhost/admin/ - To login Or Code: - Controllers PHP Code: $routes->group('auth', ['namespace' => 'App\Controllers\Auth'], function($routes) Routes: Code: http://mydevsite.vhost/auth/ - To login I think it becomes more readable. But, just a personal opinion. RE: 403 in Controller Subdirectory access - inumaru - 06-24-2020 (06-24-2020, 04:27 AM)InsiteFX Wrote: You also need to pass the sub-folder name. Well, I have no problem accessing the "admin/home", you see my question was how to redirect people accessing "/admin" to somewhere else as I got 403 when accessing it, btw I also set this in my route: PHP Code: $routes->setAutoRoute(false); RE: 403 in Controller Subdirectory access - inumaru - 06-24-2020 (06-24-2020, 05:53 AM)MatheusCastro Wrote: In this type of structure I usually use something like this: Thank you for the opinion, but my problem persist, lets say I change the file name and class (already try many things tough): Code: - Controllers the route as your suggestion is set to: PHP Code: $routes->group('admin', ['namespace' => 'App\Controllers\Admin'], function($routes) { the result is: Code: http://mydevsite.vhost/admin/ - 403 forbiden This 403 forbidden is my main problem, I have tried to set: Redirecting Routes, change file and class name both not working but if I change the folder name to something else it works, is the name "Admin" cannot be used? RE: 403 in Controller Subdirectory access - schertt - 06-24-2020 I'm not sure if this actually matters (CI might fix it internally), but according to docs CI routes use backslashes (\) to delineate namespaces and forward slashes (/) to delineate the trailing function/argument list. So Code: $routes->add("admin", "Admin/Login::index"); should be Code: $routes->add("admin", "Admin\Login::index"); Again I don't know if this would actually cause you a problem. I think the real issue is this specific line creates a route for a file called admin, not the directory itself. I think to work properly that route would need an additional forward slash: Code: $routes->add("admin/", "Admin\Login::index"); This is one level shallower than yours but these routes from an example machine do basically the same thing: Code: $routes->get('/', 'Home::index'); Any requests to <baseURL> or <baseURL>/ are served by CI's 'default' Controller, <baseURL>/login by the Login controller, etc. The other thing I'll say is that with 403 errors, you should pretty much go straight to whatever is hosting the application itself, e.g. Apache, Nginx, etc. Look through those access/error logs for a relevant message, it could be something not directly related to CI, like bad file ownership or permissions. RE: 403 in Controller Subdirectory access - inumaru - 06-24-2020 (06-24-2020, 10:15 AM)schertt Wrote: ... This really help. Thank you for pointing this, as I finally found out why I got 403 when I access "/admin". The problem occurred because I have a folder in my public directory which name is "admin". I put this folder as a place for my css, js, etc for the admin and that is why it got 403 response. So when I access Code: http://mydevsite.vhost/admin Thank you everyone for the response. RE: 403 in Controller Subdirectory access - schertt - 06-25-2020 Ah that makes sense. Glad we could help. RE: 403 in Controller Subdirectory access - Divi - 10-29-2020 (06-24-2020, 11:09 AM)inumaru Wrote:(06-24-2020, 10:15 AM)schertt Wrote: ... RE: 403 in Controller Subdirectory access - sriram_ci - 11-10-2021 (06-25-2020, 09:42 AM)schertt Wrote: Ah that makes sense. Glad we could help.Thanks cause I eneded up with exact same problem and didn't realize I had the folder in public with same name. Now its working |