I developped my app localy (where it runs fine) and wanted to upload it to a shared host to test it.
Now I get an Fatal error that says the Zend DefaultController is not found when I go to any page on my app, only the index page works... The indexcontroller also extends Default controller as my other controllers does.
the test version is visible on tbox.ues.ch, this page will work but when you go to tbox.ues.ch/tender for example it throws the error.
my code on this line is simply
use Zend\MVC\Controller\AbstractActionController ;
class TenderController extends AbstractActionController
{...
nothing special like you can see
I'm using zendskeletonapplication and my .htaccess at root folder contains
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
I already searched arround, tried out several htaccess configuration, but didn't find a solution. Problem is still the same, even if I access my app on tbox.ues.ch/public with the default .htaccess from ZF2
Does somebody has any Idea?
Just found my error...
I changed Zend\MVC... to Zend\Mvc... uppercase problem
But I find strange that it works on my localhost and not on my shared host, anyway now I know from where comes my problem
Related
I have four identical pages that only differs in some identifiers but the logic is very much the same. All of them works on localhost. Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand.
I use XAMPP 3.2.2 and Sublime for developing it on local. I moved it to GoDaddy Deluxe Linux for live. My Codeigniter version is 3.1.10.
I already tried answers from most of the questions on StackOverflow:
All controller and model names' first letters are capitalized in the file name and inside the file.
All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I have two .htaccess files, one of them is inside the application folder, and one is outside. I don't know if that's confusing the system? But I have another website on a different hosting that has the same .htaccess files and they're working okay. And anyway, if that's confusing the system, why does it only affect one of the four identical pages?
.htaccess outside application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
.htaccess inside application folder:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
All of the controllers of the four files has this up top:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI
class Question1 extends CI_Controller
{
and the rest is normal code stuff that are working on three of those four files.
In config. php I have:
$config['uri_protocol'] = 'REQUEST_URI';
and base_url is great.
Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. My routes are working okay, as well.
I'm so lost right now.
PS. I have a custom 404 page. When I input assessment.com/index.php/question1 it shows that custom 404 page. But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). I think that tells something, I just don't know what.
EDIT
Here's my routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;
I opted not to do
$route['question1'] = "Question1";
in routes because it doesn't change anything.
Check your APPLICATION ENVIRONMENT mode. You can find it on your project root_folder/index.php and at line no. 57.
define('ENVIRONMENT', 'production');
Change the ENVIRONMENT mode into the development mode, that is
define('ENVIRONMENT', 'development');
Then refresh your applications again. If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. I solved it my 404 error with this code, you can check this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Answering this for the others who might come across the same problem.
Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." So definitely it's my controller that has the problem and not my routine or .htaccess files.
Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. So, unsurprisingly, from the controller's point of view, the page doesn't exist! Hence the 404.
I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place.
I am developing an app with PHP 7.0 and implementing routes with MVC. My root folder ('/') is the 'public' directory. When I access the address 'localhost' I am redirected to index.php with have the routes available. But when I try another url to access another route, like 'localhost/contact' the server doesn't find the entry and give this message:
Not Found
The requested URL /contact was not found on this server.
I am pretty sure that the problem in on my server config (apache2 on linux mint 18), because my friend's PC works normal. I'm using a .htaccess file too inside the public directory:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
It seems to me that the server does not run index.php and tries to access the path. How could I ever force the execution of index.php to see if there is a route to the url informed?
here follows my apache2 config files.
http://pastebin.com/2mgSjWWV
http://pastebin.com/yD4RpfK8
I'm still newbee and I understand very little in server configuration. Please someone can give me a light? Thanks!
This:
RewriteRule ^.*$ - [NC,L]
It matches EVERYTHING, and since it's tagged [L], no other RewriteRules will be evaluated, so all rewriting stops here. That means a request for example.com/foo will match this rule, rewriting stops, and a literal foo file will be searched for in the file system - which doesn't exist.
And then, even if this one rule wasn't there, this next line
RewriteRule ^.*$ index.php [NC,L]
would also not work. ANY url would match it, but then strip off the relevant data, so a request for example.com/foo would be identical to a request for example.com/index.php. no query parameters would be passed in.
Your logic should be more like:
RewriteRule ^(.*)$ index.php?args=$1 [QSA,L]
which would do these sorts of translations:
example.com/foo -> example.com/index.php?args=foo
example.com/bar?baz -> example.com/index.php?args=bar&baz
After an exhaustive battery of tests, I found a solution. The htaccess file and code was fine. The problem was my server not reading the .htaccess. Editing the apache2.conf and seting 'AllowOverride All' on , finally works.
This page https://docs.bolt.cm/3.0/howto/making-sure-htaccess-works help me to solve that!
I copied a fully functional CodeIgniter app into a new server, updated the config.php base url, and setup all database parameters accordingly.
An interesting problem I'm having is that the new install (in new server) returns a 404 for all controllers I try to access. However, when navigating to the base URL, my default controller welcome.php defined in routes.php is rendered fine on the browser.
$route['default_controller'] = "welcome";
This suggests to me that CI is running OK but there may be some other routing issue I'm not figuring out.
My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
which works fine on the other server.
Any ideas what I'm doing wrong here?
Is your apache directory configuration set to AllowOverride All?
I extended the CI_Controller and made my own controller to be extended.
Now everything works fine in localhost (xampp) but when I copied the files over to my web server, I get 500 internal server error which is quite useless. Odd to me is the fact, that I get internal server error instead of codeigniter generated error.
Things I have tried so far:
1) tried libraries folder instead of core for MY_Controller
2) I have had problem with server only accepting lowercase file names so I tried my_controller and changing config file prefix, main.php extension and so on.
Both of these seems like useless tries anyways, cause I didn't get error saying it can't be found or something similar.
When I change my main.php controller to extend CI_Controller, everything works fine.
I know I haven't provided much information, but I have no idea what to provide. Again, it works in localhost.
Thanks for any input you might have.
Try changing your config.php to.
$config['index_page'] = '';
and the .htacces of the site to:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
In my Zend Framework project I have the following base URL
http://domain/~myFolder
If I access it like so, I can access the indexAction with no problem but if I try to access it explicitly like so:
http://domain/~myFolder/index
I can't, nore can I access different controllers or actions.
It always says
/public/index.php was not found on this server.
How can I access the different controllers and actions in my project? Do I need to add a route?
Change the contents of the .htaccess file according to...
From: http://framework.zend.com/manual/1.12/en/zend.application.quick-start.html
You may note that the application environment constant value looks for
an environment variable "APPLICATION_ENV". We recommend setting this
in your web server environment. In Apache, you can set this either in
your vhost definition, or in your .htaccess file. We recommend the
following contents for your public/.htaccess file:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I was able to access the controller page by putting the controller name after the index.php:
ie: yoursite/public/index.php/ControllerName
It worked in my case.