Codeigniter 4 routing not working on live server - 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: Codeigniter 4 routing not working on live server (/showthread.php?tid=77818) |
Codeigniter 4 routing not working on live server - adil - 10-21-2020 hi, i am developing a website.its working fine on local.But when i uploaded it to windows server,only default controller working.getting "Not Found The requested document was not found on this server." document root is httpdocs/public. here is the htaccess on public. Code: # Disable directory browsing Code: <IfModule mod_rewrite.c> Code: $routes->setDefaultNamespace('App\Controllers'); RE: Codeigniter 4 routing not working on live server - captain-sensible - 10-23-2020 Hi adil you should have to do anything to .htaccess until you move to https. Keep it simple get http working first . probably more important is set up of directories and the hosting what is inside "public" should be inside where the hosting is looking , htdocs or public_html or equivalent. If you packed everything else say into a directory called "CI4" and this directory is at a level above public_html on your live sever then you edit index.php to: $pathsPath = realpath(FCPATH . '../CI4/app/Config/Paths.php'); try a manual route: in Routes.php add Code: $routes->get('test','Home::test'); In Home Controller add: Code: public function test() then go in web browser to http://domain.com/test RE: Codeigniter 4 routing not working on live server - adil - 10-24-2020 Hi captain-sensible, thank you for the reply.its still the same. error "Not Found The requested document was not found on this server." my directory structure is : httpdocs app public system writable vendor .env .htaccess When i change document root from httpdocs/public to httpdocs and add public/index.php/ to url it works RE: Codeigniter 4 routing not working on live server - captain-sensible - 10-24-2020 i notice i slight duplication there ; you can try this experiment take out system and place it where it you can be put back . you should find it still works since composer is autoloading whats in vendor. you should not have httpdocs and public directory . The contents of what inside public should be inside the web root, where the server is looking for index.php, the rest should be bundled and placed at a level outside web root. have a look at attached images; my main hosting has 4 webs but on sub domain set up ; i wanted to see how it would work with one app in one hosting. Look at the directory names. there is no "public" directory thats because public_html "represents it" in other words, you need to go INSIDE your public directory and zip up contents ONLY, you then go to inside your live web root eg public_html and extract contents of the zip file you just uploaded . Everything else can be put into a directory in my case CI4 and as i said i simply edited index.php to take account of that . You can play for free on 000webhost : https://www.000webhost.com/ to prove my approach look at : https://ghanahomefood.000webhostapp.com/ Can you get any screen shots RE: Codeigniter 4 routing not working on live server - captain-sensible - 10-24-2020 also probably set $routes->setAutoRoute(false); if you have defined routes in app/Config/Routes.php RE: Codeigniter 4 routing not working on live server - paulbalandan - 10-24-2020 Can you post a screen shot of your server's filesystem structure? Check first if you do have mod_rewrite enabled. Then your web assets should not be situated in the httpdocs folders but inside the public folder. So the htaccess on httpdocs can be removed. RE: Codeigniter 4 routing not working on live server - InsiteFX - 10-24-2020 He has everything under a ci4 folder with public in the root. Needs to change path settings from what I see og the directory structure. RE: Codeigniter 4 routing not working on live server - adil - 10-25-2020 Hi thanks for the reply guys. I solved the problem. I added some lines to web config file. its on windows server. Code: <asp scriptErrorSentToBrowser="true" /> and all the directory structure is same as the original ci4 structure. I changed root dir to httpdocs to httpdocs/public. Now its working fine. |