按变量重写网址


Rewrite URL by variables

我有一个搜索表单,上面有:
1)搜索方式(所有时间设置-这是一个选择表单,selected='true')
2) 输入(仅接受 A-Z,a-z,0-9)
3)和其他2选择形式,如第一个

您可以使用所有 3 个(第 2 点除外)进行搜索,我想重写 3 个变量的 URL。当我重写所有变量时,如下所示:

RewriteRule ^servers/([a-z-]+)/([A-Za-z0-9-]+)/([a-z-]+)/([A-Z-]+)/?$   servers.php?query=$1&matching=$2&playing=$3&location=$4 [NC,L]  

我试过了

RewriteRule ^servers/([a-z-]+)/([a-z-]+)/([A-Z-]+)/?$   servers.php?query=$1&playing=$2&location=$3 [NC,L]  

但不起作用。你可以帮我吗?

<?php 
 if(isset($_POST['searchservers'])){
    $okGame = 0;
    $okLocation = 0;
    //Search Type Filter
    switch($_POST['searchtype']){
        case 'nameorip':
        case 'map':
            $query = $_POST['searchtype'];
        break;
        default:
            $query = "nameorip";
        break;
    }
    // Sentence Filter
    if(isset($_POST['matching'])){
        $matching = preg_replace('/[^A-Za-z0-9'-]/', '', $_POST['matching']);
    }
    // Game Filter
    $getGames = DB::conn()->query("SELECT abbr FROM `games`");
        while($gamee = $getGames->fetch_assoc()){
            if($_POST['game'] == $gamee['abbr']){
                $playing = $gamee['abbr'];
                $okGame = 1;
            }
        }
        if($okGame == 0){
            $playing = "allgames";
        }
        // Location Filter
        if(strlen($_POST['location']) == 2){
            $location = preg_replace('/[^A-Z'-]/', '', $_POST['location']);
            $okLocation = 1;
        }
        if($okLocation == 0){
            $location = "alllocations";
        }
        if(!isset($_POST['matching'])){
            echo '<meta http-equiv="refresh" content="0;url=/servers/'.$query.'/'.$playing.'/'.$location.'/">';
        } else {
            echo '<meta http-equiv="refresh" content="0;url=/servers/'.$query.'/'.$matching.'/'.$playing.'/'.$location.'/">';
        }
    }
?>

尝试以下操作:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^servers/([a-z-]+)/([a-z-]+)/([A-Z-]+)/?$ servers.php?query=$1&playing=$2&location=$3 [NC,L] 
RewriteRule ^servers/([a-z-]+)/([A-Za-z0-9-]+)/([a-z-]+)/([A-Z-]+)/?$ servers.php?query=$1&matching=$2&playing=$3&location=$4 [NC,L] 
</IfModule>

当我导航到 http://localhost/servers/a/b/c/d/或 http://localhost/servers/a/b/c/时,它似乎有效

确保根目录中确实有服务器.php或相应地更改重写库。