Why do my routes only work on the localhost and not on the Web server?

Asked

Viewed 130 times

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.

  • 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]

  • your web server is apache or ngix?

  • 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.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.