0
I am a developer .NET (Desktop apps & mobiles) trying to get on the web PHP for being a free Lang and her FDI’s are light. I created my MVC (as a beginner I preferred not to use frameworks) and the local machine is ball show. But why when I migrate it to a server gives problem in routes? Stop changing page, just keep DEFAULT (Home). What’s wrong with my code?
public static function route($url) {
// my default controller
define('DEFAULT_CONTROLLER', 'Home');
// controller
$controller = (isset($url[0]) && $url[0] != '') ? ucwords($url[0]) : DEFAULT_CONTROLLER;
$controller_name = $controller;
array_shift($url);
// action
$action = (isset($url[0]) && $url[0] != '') ? $url[0] . 'Action': 'indexAction';
$action_name = $controller;
array_shift($url);
$queryParams = $url;
$dispatch = new $controller($controller_name, $action);
if (method_exists($controller, $action)) {
call_user_func_array([$dispatch, $action], $queryParams);
} else {
header("Location: ../_404");
}
}
}
File . htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(config|core|css|js|fonts|robots\.txt)
RewriteRule ^(.+)$ index.php/$1 [L]
Sometimes the problem is not in the code, but in the configuration of the
htaccess
or server.– Valdeir Psr
That my htaccess, I see no error or must be missing flags? My Server n uses the public folder ja botei ate Rewritebase / even so nothing!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond $1 !^(config|core|css|js|fonts|robots\.txt)
RewriteRule ^(.+)$ index.php/$1 [L]
– Jorge Dacosta
your web server is apache or ngix?
– Will Knippelberg
Hello @Willknippelberg, thanks for taking the time to reply, actually my problem has already been solved. I was running an Apache server and my error was in the file
.htaccess
.– Jorge Dacosta