Trying to remove index.php from url in latest codeigniter 4.5.1 |
Hi
I've started a new codeigniter 4.5.1 appstarter project at my PC and am having difficult time to remove the index.php from uri 1) This is the virtualhost set in my Apache. Points at public as suggested Code: <VirtualHost *:80> 2) I've enabled the mod_rewrite, restarted apache, edited /etc/hosts file. Then I browse to http://sw , which shows the codeigniter welcome, great! 3) I rename the root/env file to .env and leave it with Code: #-------------------------------------------------------------------- 4) I define a new route in app/config/Routes.php Code: $routes->get('/services', 'Services::index'); Then, my controller app/Controllers/Services.php looks like PHP Code: <?php Then, when I try this url in browser http://sw/services I'm getting 404 ... 5) Tried also replacing the public/.htaccess with the suggested in https://codeigniter.com/user_guide/gener...x-php-file No luck 6) I've also tried setting the baseURL, indexPage, etc. options in app/Config/App.php without luck I've got no ideas left to solve this Thanks for any suggestion
Enrique
https://beza.com.ar
Try go in App/Config/app then
PHP Code: public string $indexPage = 'index.php'; /*===*/ /*remove index.php*/ public string $indexPage = ''; Codeigniter First, Codeigniter Then You!!
yekrinaDigitals
(05-02-2024, 08:57 AM)kabeza Wrote: Then, when I try this url in browser The exact error message matters. If Apache returns the error before running CI4, CI4 cannot do anything. (05-02-2024, 09:44 AM)Bosborne Wrote: Does the file 'view_services' exist in the app/Views folder? Yes. When using index.php in the url, I've checked the controller/view worked fine (05-02-2024, 03:51 PM)luckmoshy Wrote: Try go in App/Config/app then Yes, as stated in original post, I've tried that in .env file and app/Config/App.php also, without luck (05-02-2024, 05:18 PM)kenjis Wrote:(05-02-2024, 08:57 AM)kabeza Wrote: Then, when I try this url in browser Yes, the url works great with index.php but when I remove it Apache throws 404. Gonna check if I can do anything related to Apache and will update in case I succeed. Thanks
Enrique
https://beza.com.ar
Another way : Go to Public folder, move (or copy) htaccess and index.php to the main app folder. Then in your main app/index.php find the line 34 and change the path like
PHP Code: require FCPATH . 'app/Config/Paths.php';
If you want to open a page like http://sw/services
you have to remove the "/" in the Config/Routes.php like this: Code: $routes->get('services', 'Services::index'); (05-03-2024, 05:31 AM)demyr Wrote: Another way : Go to Public folder, move (or copy) htaccess and index.php to the main app folder. Then in your main app/index.php find the line 34 and change the path like The virtualhost is pointing (as recommended in user_guide) to the public folder, so moving/copying the index.php and .htaccess from public to app/ didn't work (05-08-2024, 02:56 AM)elbambolo Wrote: If you want to open a page like http://sw/services With or without "/" didn't work I've finally solved it by getting the appStarter again working from scratch in another folder/virtualhost Then moved to the non-working application all the files, mainly the ones from app/Config and again overwriting everything from /vendor/codeigniter4/framework/app/Config Don't know which file from app/Config was making conflict, but maybe I've touched or edited something that didn't make it work Thanks 2 everyone
Enrique
https://beza.com.ar |
Welcome Guest, Not a member yet? Register Sign In |