Codeigniter 4 routing not working on live server |
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');
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
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
10-24-2020, 02:30 AM
(This post was last modified: 10-24-2020, 02:31 AM by captain-sensible. Edit Reason: added images via full edit )
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
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.
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. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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. |
Welcome Guest, Not a member yet? Register Sign In |