未找到Webhosting文件

时间:2017-07-20 22:26:12

标签: php

我和问题打了很长时间。我刚刚将php mvc应用程序从本地服务器复制到了webhosting(http://www.fandasoft.cz),但是当我尝试提交表单时,或者只是添加斜杠和fandasoft.cz / home这样的东西我找不到404文件 - 甚至不是我自己的404页面。错误日志中只有错误'主要脚本未知\ n'。所有代码都在github上(抱歉,这是捷克语)。我错过了什么?感谢。

.htaccess
# aktivace prepisovaciho mechanizmu pro URL
RewriteEngine On

# zakaz zobrazovani obsahu adresaru
# 403 pro adresare ktere neobsahuji index soubor
Options -Indexes
#Options +FollowSymlinks

# zakladni adresa pro prepisovani. Je potreba pokud aplikaci mame v podadresari.
#<If "%{HTTP_HOST} == ^\d+\.'">

#ErrorDocument 404 app/
# Prepisovaci podminky
# viz: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewritecond
# nebudeme prepisovat URL pro existujici adresare
RewriteCond %{REQUEST_FILENAME} !-d
# ani pro existujci soubory
RewriteCond %{REQUEST_FILENAME} !-f
# ani pro symbolicke odkazy
RewriteCond %{REQUEST_FILENAME} !-l
# prepis vsechna splnujici podminky na tvar index.php s parametrem url
# vice zde: http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
#RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

RewriteRule ^(.+)$ index.php/$1 [QSA,L]
#!\.(css|js|icon|zip|rar|png|jpg|gif|pdf)$

index.php
<?php
use app\Bootstrap;
require('app/config.php');
require_once('app/error_handler.php');
//nastav autoloading
spl_autoload_extensions('.php');
spl_autoload_register();
session_start();
require_once 'vendor/autoload.php';
$app = new Bootstrap();
?>

bootstrap.php
<?php

namespace app;

use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\ValidationData;
use Lcobucci\JWT\Parser;
use app\modely\pobocka;

class Bootstrap {

    private $kontroler;
    private $akce;
    private $parametry = array();

    public function __construct() {
        $this->parsujUrl();
        $this->routuj();
    }

    private function routuj() {

        if ($this->kontroler) {
            $trida = "app\\kontrolery\\" . $this->kontroler;
            $soubor = "app/kontrolery/" . $this->kontroler . ".php";

            if (is_readable($soubor)) {
                $handler = new $trida();

                if ($this->akce && method_exists($handler, $this->akce)) {
                    $handler->{$this->akce}($this->parametry);
                    return true;
                } elseif (!$this->akce) {
                    var_dump($this->kontroler);
                    $handler->index();
                    var_dump('OK');
                    return true;
                } else {
                    $handler = new kontrolery\Error();
                    $handler->error404();
                    return true;
                }
            } else {
                $handler = new kontrolery\Error();
                $handler->error404();
                return true;
            }
        } else {
            $handler = new kontrolery\Home();
        }
        $handler->index();
    }

    private function parsujUrl() {
        $url = $_SERVER['REQUEST_URI'];
        $url = filter_var($url, FILTER_SANITIZE_URL);
        if (ENVIRONMENT === 'DEV') {
            $pos = strpos($url, ROOT_DIR);
        } else {
            $pos = true;
//            $url = rtrim($url,"/");
        }
        if ($pos == false) {
            $url = substr_replace($url, '', $pos, strlen(ROOT_DIR));
        }

        $url = 'pobocka/nastav/';
        $parsovanaUrl = parse_url($url);
        var_dump($parsovanaUrl);
        $path = array_filter(explode('/', !empty($parsovanaUrl['path']) ? $parsovanaUrl['path'] : null));

        if (empty($path[0])) {
            $this->kontroler = null;
        } else if (count($path) > 2) {
            $this->kontroler = 'Error';
        } else {
            $this->kontroler = $path[0];
        }

        var_dump($this->kontroler);

        $this->akce = !empty($path[1]) ? $path[1] : null;

        if (!empty($parsovanaUrl['query'])) {
            preg_match_all('([\w]+=[\w\d]+)', $parsovanaUrl['query'], $par);
            foreach ($par[0] as $p) {
                $this->parametry[explode('=', $p)[0]] = explode('=', $p)[1];
            }

        }

        // POST jako parametry pro jednoduchou praci s formulari
        foreach ($_POST as $k => $v) {
            $this->parametry[$k] = $v;
        }


        $token = !empty($_COOKIE[COOKIE_POBOCKA]) ? $_COOKIE[COOKIE_POBOCKA] : null;
        $signer = new Sha256();

        $data = new ValidationData(); // It will use the current time to validate (iat, nbf and exp)
        $data->setIssuer(WEB_URL);
        $data->setAudience(WEB_URL);

        try {
            $token = (new Parser())->parse($token);
            if (!$token->verify($signer, SIGN_JWT) || !$token->validate($data)) {
                $this->presmeruj();
            } else {
                $pobocka = json_decode($token->getClaim("pobocka"));
                $_SESSION[SESSION_POBOCKA] = new Pobocka($pobocka->id, $pobocka->id_pobocka, $pobocka->nazev, $pobocka->heslo, $pobocka->mesto);
            }
        } catch (\Exception $exception) {
            $this->presmeruj();
        }

    }

    private function presmeruj() {
        if ($this->kontroler == "zaznam" && $this->akce == "vratInfoZbozi") {

        } elseif ($this->kontroler != "pobocka" && $this->kontroler != "home") {
            $this->kontroler = 'home';
            $this->akce = '';
            $this->parametry = '';
            unset($_SESSION['uzivatel']);
            unset($_SESSION[SESSION_POBOCKA]);
        }
    }

}

1 个答案:

答案 0 :(得分:0)

我唯一需要改变的是来自

的.htaccess
#RewriteRule ^(.+)$ index.php/$1 [QSA,L]

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

现在它工作正常。