dou11655853 2017-07-20 22:26
浏览 47
已采纳

未找到Webhosting文件

I'm fighting for a long time with problem. I've just copied php mvc application from local server to webhosting (http://www.fandasoft.cz), but when I try for example submit the form, or just add slash and anything like fandasoft.cz/home I got 404 File not found - and not even my own 404 page. In error log is just Got error 'Primary script unknown '. All code is on github (sorry, it's czech). What am I missing? Thanks.

.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条回答 默认 最新

  • duanbianweng5353 2017-07-21 08:09
    关注

    The only thing I had to change was in .htaccess from

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

    to

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

    now it's working fine.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号