检查URL中传递的参数是否为目录

时间:2019-10-10 23:09:52

标签: php .htaccess url

我使用了同样的友好URL逻辑,并且运行良好,我在检查目录时遇到了麻烦,而不是显示消息,而是将其重定向到URL中键入的目录。

URLDynamic.class.php

class URLDynamic
{
    private $ArrayParam;
    public  $param;
    public  $sepURL;

    public function ArrayParam()
    {
        if ( isset ( $_GET['url'] ) ) :
            $this->param  = addslashes ( rtrim ( $_GET['url'] ) );
            $this->sepURL = array_filter ( explode ( "/", $this->param ) );
        endif;

    }

    private function PushParam()
    {
        $this->ArrayParam = $this->ArrayParam();

        if ( isset ( $_GET['s'] ) ) :

            $Search = new Search;
            $Search->GetSearch();

        elseif ( isset ( $this->sepURL[0] ) ) :

            if ( is_dir ( $this->sepURL[0] ) ) :
                echo "Error 404";
            else :
            endif;  

        else :

            $Home = new Home;
            $Home->GetHome();

        endif;

    }

    public function GetURL()
    {
        return $this->PushParam();
    }
}

.htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1

0 个答案:

没有答案
相关问题