Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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/8/.htaccess/6.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 .htaccess,can';不要在LAMP中重写url_Php_.htaccess_Mod Rewrite_Url Rewriting_Lamp - Fatal编程技术网

Php .htaccess,can';不要在LAMP中重写url

Php .htaccess,can';不要在LAMP中重写url,php,.htaccess,mod-rewrite,url-rewriting,lamp,Php,.htaccess,Mod Rewrite,Url Rewriting,Lamp,我在重写url时遇到问题。似乎当我试图通过.htaccess文件设置GET值时,它不起作用,但当我执行类似localhost/project/?url=index/contact的操作时,它就起作用了 这是我的.htaccess文件 RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.+)$ index.p

我在重写url时遇到问题。似乎当我试图通过
.htaccess
文件设置GET值时,它不起作用,但当我执行类似
localhost/project/?url=index/contact
的操作时,它就起作用了

这是我的.htaccess文件

    RewriteEngine On

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

    RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
我的项目看起来像:

    --app/
    ----controllers/
    ----libraries/
    ----views/
    ----models/
    --public/
    ----css/
    ----images/
    index.php
    .htaccess
引导文件:

class bootstrap
{
    public function __construct()
    {
        $url = isset($_GET['url'])? $_GET['url'] : null;
        $url = rtrim($url, '/');
        $url = explode('/', $url);

        if(empty($url[0]))
        {
            require 'app/controllers/index.php';
            $controller = new index();
            $controller->indexAction();
            $controller->loadModel('index');
            $controller->view->render('index','index');
            return false;
        }

        $file = 'app/controllers/'.$url[0].'.php';
        if(file_exists($file))
        {
            require $file;
        }
        else
        {
            error::noController();
        }

        $controller = new $url[0]();
        $controller->loadModel($url[0]);

        if(!isset($url[1]))
        {
            if(method_exists($controller, 'indexAction'))
            {
                $viewFile = 'app/views/'.$url[0].'/index.phtml';
                if(file_exists($viewFile)) {
                    $controller->indexAction();
                    $controller->view->render($url[0],'index');
                }
                else
                    error::noView();
            }
            else
            {
                error::noMethod();
            }
        }

        if(isset($url[2]))
        {
            $action = $url[1].'Action';
            $controller->$action($url[2]);
            $controller->view->render($url[0], $url[1]);
        }
        else
        {   
            if(isset($url[1]))
            {
                $action = $url[1].'Action';
                if(method_exists($controller, $action))
                {
                    $controller->$action();
                    if(file_exists('app/views/'.$url[0].'/'.$url[1].'.phtml'))
                        $controller->view->render($url[0],$url[1]);
                    else
                        error::noView();
                }
                else
                {
                    error::noMethod();
                }
            }
        }
    }
    }
?>

您是否已使用
var\u dump($\u GET)
进行调试?假设没有其他重写规则,则.htaccess内容看起来是正确的。您是否验证了.htaccess文件是以开头解析的(服务器/虚拟主机的
AllowOverride
设置正确)?这个变量转储的结果是“array(0){}”,我将AllowOverride设置为allI。我注意到,当我在url中键入例如“contact”时,它工作正常。当我键入“index”时,问题开始出现,然后$\u GET array为空。您是否在Apache中为该目录启用了
MultiViews
?这可能会导致
/index
出现问题。禁用
多视图有帮助,谢谢。