Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.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包含多个参数的干净Url_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Php .htaccess包含多个参数的干净Url

Php .htaccess包含多个参数的干净Url,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,我是php和htaccess的新手,这是我的第一篇文章。我的URL有问题,我只是想把它弄干净。顺便说一下,我现在的网址是 http://www.example.com/index.php?page=home&lesson=1.1 我怎样才能把它改成 http://www.example.com/home/1.1/ 这是我的index.php代码 对了,伙计们。我希望我的网址看起来漂亮和干净,我也想征求你的意见,我可以做什么其他事情,使我的网站更安全。我希望有人能帮助我。您可以在文档

我是php和htaccess的新手,这是我的第一篇文章。我的URL有问题,我只是想把它弄干净。顺便说一下,我现在的网址是

http://www.example.com/index.php?page=home&lesson=1.1 
我怎样才能把它改成

http://www.example.com/home/1.1/
这是我的index.php代码


对了,伙计们。我希望我的网址看起来漂亮和干净,我也想征求你的意见,我可以做什么其他事情,使我的网站更安全。我希望有人能帮助我。

您可以在文档\u ROOT/.htaccess文件中使用此代码:

<?php
    include("page_check.php"); // this is where the program check what is the requested page. 
    include($page); // it could be home.php, login.php and etc
    include("templates/layout.php"); //the template, contains HTML tags...
?>
<?php
    session_start();
    $page = $_GET['page'];
    $array_page=array('home','create_group','group','try_it_out','logout');
    $page_no_session=array('login','register','email_confirmation');
    $len;
    if (!empty($_SESSION['login_state'])){
        $len = count($page_no_session);
        for($i = 0; $i < $len; $i++){
            if ($page_no_session[$i] == $page){
                $page = "home";
            }
        }
        if(empty($page)){
            $page = "home";
        }
    }
    else{
        if(empty($page) AND empty($_SESSION['login_state'])){
            $page = "login";
        }
        else{
            $len = count($array_page);
            for($i = 0;$i < $len;$i++){
                if ($array_page[$i] == $page){
                $page = "login";
                }
            }
        }
    }
        $page = "$page.php"; //this is what I'm telling, it could be home.php, login.php and etc.. defends upon the requested php file
?>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&lesson=$2 [L,QSA]