如何使用$_GET参数来制作seo友好的url?

Int*_*Dev 2 php .htaccess seo get

我正在使用我自己制作的 PHP CMS。它获取 $_GET 参数url并将其转换为www.website.com/{url}. 此 CMS 使用 $_GET 参数来获取文件。因此,如果urlindex,则 CMS 会搜索该文件index并返回该文件的内容。但现在,我正在扩展 CMS 以添加一个附加参数,例如profile/{username}. 我该如何扩展它?我希望我的网址说www.website.com/profile/{username}. 我该怎么做呢?这是我当前的 htaccess:

RewriteEngine On  
RewriteRule ^(|/)$ index.php?url=$1  
RewriteRule ^([a-zA-Z0-9_-]+)(|/)$ index.php?url=$1a
Run Code Online (Sandbox Code Playgroud)

这是TPL系统。

public function addTpl() {     
    global $zip;

    if(!isset($_GET['url']) || empty($_GET['url'])) {
        $_GET['url'] = 'index';
    }

    if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/')) {
        if(file_exists('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php')) {
            ob_start();
            include('_zip/_templates/_front/'. $zip['Template']['Front'] . '/' . secure($_GET['url']) . '.php');
            $this->tpl .= ob_get_contents();
            ob_end_clean();
        } else {
            die(zipError('File Not Found', 'The file <b>' . secure($_GET['url']) . '</b> could not be found. Please re-check the URL; If you were directed here using a link, please report that link.'));
        }
    } else {
        die(zipError('Template Not Found', 'The template <b>' . $zip['Template']['Front'] . '</b> could not be found. Please check your configuration file for a mistake.'));
    }
}
Run Code Online (Sandbox Code Playgroud)

我还需要提供其他信息吗?我需要尽快完成这项工作,所以任何建议将不胜感激。

php*_*_qq 5

在包含该文件之前,您可以将第二个参数 ( {username} ) 设为局部变量,然后您可以在其中将其作为普通变量进行访问。如果您与团队合作,这不是一件好事。

编辑

您可以执行以下操作

RewriteEngine On  
RewriteRule ^ index.php
Run Code Online (Sandbox Code Playgroud)

然后在index.php中你可以有这个

$url = str_replace('index.php','', $_SERVER['PHP_SELF']);
$url = str_replace($url,'',$_SERVER['REQUEST_URI']);
$url = explode('/',$url);
$page = array_shift($url);
foreach ($url as $val){
    $args[] = urldecode($val);
}
Run Code Online (Sandbox Code Playgroud)

现在,如果您打开链接,www.website.com/profile/someuser/about您将看到

$page = 'profile'
$args[0] = 'someuser'
$args[1] = 'about'
Run Code Online (Sandbox Code Playgroud)

等等,你可以有尽可能多的争论。