php - Rewrite URL by variables -


i have search form with:
1) search (all time set - it's select form selected='true')
2) input (with accept a-z,a-z,0-9)
3) , other 2 select form first

you can search 3 (except point 2) , want rewrite url 3 variables. when have variables rewrite looks like:

rewriterule ^servers/([a-z-]+)/([a-za-z0-9-]+)/([a-z-]+)/([a-z-]+)/?$   servers.php?query=$1&matching=$2&playing=$3&location=$4 [nc,l]   

i tried

rewriterule ^servers/([a-z-]+)/([a-z-]+)/([a-z-]+)/?$   servers.php?query=$1&playing=$2&location=$3 [nc,l]   

but doesn't work. can me ?

<?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 `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.'/">';         }     } ?> 

try following:

<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> 

it seemed work when navigated http://localhost/servers/a/b/c/d/ or http://localhost/servers/a/b/c/

make sure have servers.php in root directory or change rewritebase accordingly.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -