Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Apache重写:找不到文件_Php_Apache_.htaccess_Mod Rewrite_Apache2 - Fatal编程技术网

Php Apache重写:找不到文件

Php Apache重写:找不到文件,php,apache,.htaccess,mod-rewrite,apache2,Php,Apache,.htaccess,Mod Rewrite,Apache2,我正在开发一个应用程序,使用apache的.htaccess将URL重写到应用程序中的不同模块。当我尝试浏览我的应用程序时,出现以下错误: 在此服务器上找不到请求的URL/var/www/dynamicsuite/index.php 但是/var/www/dynamicsuite/index.php确实存在!我尝试使用chmod777查看是否存在权限问题,但仍然无法正常工作 以下是文件的总体布局以及我要完成的工作: /var/www/app - Main Dire

我正在开发一个应用程序,使用apache的.htaccess将URL重写到应用程序中的不同模块。当我尝试浏览我的应用程序时,出现以下错误:

在此服务器上找不到请求的URL/var/www/dynamicsuite/index.php

但是/var/www/dynamicsuite/index.php确实存在!我尝试使用chmod777查看是否存在权限问题,但仍然无法正常工作

以下是文件的总体布局以及我要完成的工作:

/var/www/app                 - Main Directory
/var/www/app/index.php       - This is what I rewrite too
/var/www/app/modules/login   - The login form
/var/www/app/modules/home    - The homepage on login
/var/www/app/modules/error   - Error page if something goes wrong
当用户转到应用程序时,它将查看他们是否登录,并将他们重定向到适当的模块。我使用mod_rewrite是因为我不希望用户必须指定一个长URL,例如mysite.com/app/modules/login。相反,我让它成为mysite.com/app/login。URL中模块名称之后的所有内容都将使用我编写的类/方法作为变量处理。例如:

mysite.com/app/error/404/time/user/etc
vs

以下是我在.htaccess文件中使用的代码:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l

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

AddDefaultCharset UTF-8
注意:我使用PT标志是因为我在应用程序中使用别名

将Ubuntu 14.04与apache2、mod_重写、mod_别名一起使用

你可以在这里看到它:

以下是使用的其他文件:

配置

$cfg["install_dir"] = array("ds", "employee", "dynamicsuite");
index.php

// Required Scripts
require_once("config/config.php");

function __autoload($class) {
    require_once("core/lib/$class.class.php");
}

if(!dsDatabase::dbCheck()) {
    dsInstance::genericError(1);
    exit;
}

// Process the URI and direct the user to the proper module
elseif(!isSet(dsInstance::getUri()[0])){

    // If a session if found, skip the login page and render the homepage
    if(dsSession::checkSession() === true) {
        header("Location: home");
    }

    // If no session is found, render the login page
    else {
        header("Location: login");
    }

}

// If the module exists, render it
elseif(file_exists("modules/" . dsInstance::getUri()[0])) {
    require_once("modules/" . dsInstance::getUri()[0] . "/index.php");
}

// If no conditions are met, render the error page
else {
    dsInstance::genericError(404);
}
getUri()函数:

public static function getUri() {

    global $cfg;

    if(strpos($_SERVER["REQUEST_URI"], "?") != false) {
        $uri = explode("/",      trim(substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],"?")),"/"));
    } else {
        $uri = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
    }

    $search = in_array($uri[0], $cfg["install_dir"]);

    if($search === true) {
        return array_splice($uri, 1, count($uri));
    } else {
        return $uri[0];
    }

}
public static function dbCheck() {

    global $cfg;

    try {

        $db = new PDO($cfg['db_type'] . ":host=" .
                      $cfg['db_host'] . ";dbname=" .
                      $cfg['db_name'],
                      $cfg['db_user'],
                      $cfg['db_pass']);

    } catch (Exception $e) {
        return 0;
    }

    return 1;
}
public static function checkSession() {

    if(isSet($_SESSION["DS_SESSION"])) {
        return true;
    } else {
        return false;
    }

}
public static function genericError($code) {
    $location = dsInstance::getUri()[0];
    $time = time();
    header("Location: error/$code/$location/$time");
}
dbCheck()函数:

public static function getUri() {

    global $cfg;

    if(strpos($_SERVER["REQUEST_URI"], "?") != false) {
        $uri = explode("/",      trim(substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],"?")),"/"));
    } else {
        $uri = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
    }

    $search = in_array($uri[0], $cfg["install_dir"]);

    if($search === true) {
        return array_splice($uri, 1, count($uri));
    } else {
        return $uri[0];
    }

}
public static function dbCheck() {

    global $cfg;

    try {

        $db = new PDO($cfg['db_type'] . ":host=" .
                      $cfg['db_host'] . ";dbname=" .
                      $cfg['db_name'],
                      $cfg['db_user'],
                      $cfg['db_pass']);

    } catch (Exception $e) {
        return 0;
    }

    return 1;
}
public static function checkSession() {

    if(isSet($_SESSION["DS_SESSION"])) {
        return true;
    } else {
        return false;
    }

}
public static function genericError($code) {
    $location = dsInstance::getUri()[0];
    $time = time();
    header("Location: error/$code/$location/$time");
}
checkSession()函数:

public static function getUri() {

    global $cfg;

    if(strpos($_SERVER["REQUEST_URI"], "?") != false) {
        $uri = explode("/",      trim(substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],"?")),"/"));
    } else {
        $uri = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
    }

    $search = in_array($uri[0], $cfg["install_dir"]);

    if($search === true) {
        return array_splice($uri, 1, count($uri));
    } else {
        return $uri[0];
    }

}
public static function dbCheck() {

    global $cfg;

    try {

        $db = new PDO($cfg['db_type'] . ":host=" .
                      $cfg['db_host'] . ";dbname=" .
                      $cfg['db_name'],
                      $cfg['db_user'],
                      $cfg['db_pass']);

    } catch (Exception $e) {
        return 0;
    }

    return 1;
}
public static function checkSession() {

    if(isSet($_SESSION["DS_SESSION"])) {
        return true;
    } else {
        return false;
    }

}
public static function genericError($code) {
    $location = dsInstance::getUri()[0];
    $time = time();
    header("Location: error/$code/$location/$time");
}
genericError()函数:

public static function getUri() {

    global $cfg;

    if(strpos($_SERVER["REQUEST_URI"], "?") != false) {
        $uri = explode("/",      trim(substr($_SERVER["REQUEST_URI"],0,strpos($_SERVER["REQUEST_URI"],"?")),"/"));
    } else {
        $uri = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
    }

    $search = in_array($uri[0], $cfg["install_dir"]);

    if($search === true) {
        return array_splice($uri, 1, count($uri));
    } else {
        return $uri[0];
    }

}
public static function dbCheck() {

    global $cfg;

    try {

        $db = new PDO($cfg['db_type'] . ":host=" .
                      $cfg['db_host'] . ";dbname=" .
                      $cfg['db_name'],
                      $cfg['db_user'],
                      $cfg['db_pass']);

    } catch (Exception $e) {
        return 0;
    }

    return 1;
}
public static function checkSession() {

    if(isSet($_SESSION["DS_SESSION"])) {
        return true;
    } else {
        return false;
    }

}
public static function genericError($code) {
    $location = dsInstance::getUri()[0];
    $time = time();
    header("Location: error/$code/$location/$time");
}

谢谢

我似乎已经解决了这个问题(感谢zx81将问题缩小到别名!)


通过将mod_rewrite指令RewriteBase添加到my.htaccess文件中,它现在似乎可以按预期工作。

TL;博士信任错误消息。您认为文件在那里,但您给出的路径显然不适用于Apache。。。Apache正在从web文档根目录中查找文件,文档根目录下是否有
var
文件?所涉及的文件位于web根目录下,我设置了一个别名来指向它。应用程序位于web根目录下的一个目录中。(App:/var/www | Web Root:/var/www/html)。它给出的错误中的文件确实存在,尽管我使用别名浏览它。从您所说的,我觉得web根目录(即公开访问的文件)是
/var/www/html
,因此Apache无法返回
/var/www/dynamicsuite/index.php
。该文件必须位于
html
以下的某个位置通常您是正确的,但我已创建了一个别名以允许apache访问该文件,这是cfg。暂时不使用别名来尝试一下如何?马上。为下一个人;如果使用“alias”公开文件夹(如公用文件夹或web文件夹),则需要“RewriteBase”。