How to do the right URL's



  • Hello, everyone. There are references.

     http://mydomen.com/search.php?q=love+film 
     http://mydomen.com/search.php?q=prostokey+zaposi 
     http://mydomen.com/search.php?q=key1+key2+key3+key4 
    

    How to ensure that, in searching for the first word, references of this kind are made and made

     http://mydomen.com/love/love+film 
     http://mydomen.com/prostokey/prostokey+zaposi 
     http://mydomen.com/key1/key1+key2+key3+key4 
    

    Only the php should be implemented. I looked in the interior, but I couldn't find it. SPASIB



  • //.htaccess
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php [L]
    
    //index.php
    <?php
    $uri_deep = 0; // глубина в подпапках, по умолчанию 0 если сайт лежит в корне
    
    $route = explode('/', $_SERVER['REQUEST_URI']); 
    $route = array_filter($route);
    array_splice($route, 0, $uri_deep);
    if (empty($route[0])) { $route[0] = 'index'; }
    
    //var_dump($route);
    ?>
    

    You'll get a mass of $route about this type, already with empty filters and slurry at the end:

     http://domain.com/module/controller/parametr1/parametr2////parametrN/ 
    

    [0] => module
    [1] => controller
    [2] => parametr1
    [3] => parametr2
    [4] => parametrN

    And then you do what you want with the mass, you can do...

    $mod_path = '/module_path/';
    $exe_mod_file = $mod_path . $route[0] . '.php'; // полный путь к модулю

    if (file_exists($exe_mod_file)) { Include_once($exe_mod_file); }
    else { header("HTTP/1.1 404 Not Found"); Include_once ($mod_path . '404.php'); }


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2