Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.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
Php Apache-htaccess 500内部服务器错误_Php_Apache_.htaccess - Fatal编程技术网

Php Apache-htaccess 500内部服务器错误

Php Apache-htaccess 500内部服务器错误,php,apache,.htaccess,Php,Apache,.htaccess,我正在学习如何制作PHP MVC应用程序,我遵循的教程涉及创建两个.htaccess文件——一个用于防止用户导航到应用程序文件夹和文件;另一个是重写URL的显示方式,以便我解析和检索控制器、方法和参数 在我的XAMPP服务器上部署这些文件时,它们工作正常。但是,当通过FTP将这些文件部署到我的大学服务器上时,会出现500内部服务器错误,删除这些文件将允许我查看我的应用程序。但我需要这些文件,否则我无法调用相应的控制器、模型和视图 我到处寻找答案,很多解决方案都说可能有语法错误,我不相信我有任何语

我正在学习如何制作PHP MVC应用程序,我遵循的教程涉及创建两个
.htaccess
文件——一个用于防止用户导航到应用程序文件夹和文件;另一个是重写URL的显示方式,以便我解析和检索控制器、方法和参数

在我的XAMPP服务器上部署这些文件时,它们工作正常。但是,当通过FTP将这些文件部署到我的大学服务器上时,会出现
500内部服务器错误
,删除这些文件将允许我查看我的应用程序。但我需要这些文件,否则我无法调用相应的控制器、模型和视图

我到处寻找答案,很多解决方案都说可能有语法错误,我不相信我有任何语法错误,因为它在XAMPP实例上工作得很好。其他答案是,服务器本身可能没有配置为允许我上传此类文件或类似内容

我无法访问我所在大学服务器的配置,我知道这可能会妨碍您向我提供的任何解决方案。因此,如果有任何PHP解决方案可用于至少让我以我需要的方式解析URL,我很乐意删除
.htaccess
文件

第一个
.htaccess
文件,位于应用程序的应用程序目录中:

Options -Indexes
Options -MultiViews
RewriteEngine On

RewriteBase /~21249593/Internet_Technologies/Element_2/public

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

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
第二个
.htaccess
文件;位于我的应用程序的公共目录中:

Options -Indexes
Options -MultiViews
RewriteEngine On

RewriteBase /~21249593/Internet_Technologies/Element_2/public

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

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
PHP类用于解析URL以调用适当的控制器及其方法,我已经发布了完整的逻辑,以便您了解解析的工作原理:

class App {
    protected $controller = 'home';
    protected $method = 'index';
    protected $params = array();

    public function __construct() {
        $url = $this->parseUrl();

        if (file_exists('../app/controllers/' . $url[0] . '.php')) {
            $this->controller = $url[0];
            unset($url[0]);
        }

        require_once '../app/controllers/' . $this->controller . '.php';

        $this->controller = new $this->controller;

        if (isset($url[1])) {
            if (method_exists($this->controller, $url[1])) {
                $this->method = $url[1];
                unset($url[1]);
            }
        }

        $this->params = $url ? array_values($url) : array();

        call_user_func_array([$this->controller, $this->method], $this->params);
    }

    public function parseUrl() {
        if (isset($_GET['url'])) {
            return $url = explode('/', filter_var(rtrim($_GET['url'], '/'), FILTER_SANITIZE_URL));
        }
    }
}
我很感激你在这里能给我的任何帮助

编辑


我应该说明XAMPP使用的是2.4.9 Apache,FTP使用的是2.2.3,这似乎是修改或重写。您的帐户通常禁止使用htaccess。您应该询问您的管理部门这是否可以更改,如果不能,您就不能使用mod_重写URL


无论如何,您可以使用像
http://yourdomain/index.php?url=something
,无论如何这些都应该有效。对于任何“更干净”的内容,您都需要更改服务器配置。

如果您无法重写URL,则必须将指向应用程序的链接更改为应用程序需要的格式

因此,不要链接到mydomain.com/controller/method/param1/param2。。。您需要链接到mydomain.com/index.php?url=controller/method/param1/param2


链接不再那么漂亮了,但它们会起作用

尝试更改“.htaccess”文件的“编码”。这对我有用。我使用了ANSI。

XAMPP上的版本(Apache、PHP)与大学FTP上的版本相同吗?FTP服务器上是否启用了模式重写?如果没有,则尝试启用它,通常通过执行命令
a2enmod rewrite
,然后不要忘记重新启动web服务器实例。此外,您还需要检查错误日志,看看到底出了什么问题。@anubhava htaccess文件不在站点的根目录下,根目录是/~21249593/@TomHart抱歉,应该说明,FTP服务器是Apache是2.2.3,XAMPP是2.4.9。@Ma'moonAl-Akash我不知道,我不知道这台服务器的配置,我们所做的只是上传到它。