How to make Friendly URLs?

0

This takes it from the Internet but I do not know what order it will have in the folders so I look for a way to test this code using ways to test this code to verify if it is ok and continue my mvc study.

index.php

<?php

$router = $_SERVER['REQUEST_URI'];
if (strpos($router,'?') ) {
  $router = strstr($router,'?',true);
}
function router($url, $closure) {
    $route = $_SERVER['REQUEST_URI'];
    if (strpos($route, '?')) {
        $route = strstr($route, '?', true);
    }

    $urlRule = preg_replace('/:([^\/]+)/', '(?<>[^/]+)', $url);
    $urlRule = str_replace('/', '\/', $urlRule);

    preg_match_all('/:([^\/]+)/', $url, $parameterNames);


    if (preg_match('/^' . $urlRule . '\/*$/s', $route, $matches)) {

        $parameters = array_intersect_key($matches, array_flip($parameterNames[1]));
        call_user_func_array($closure, $parameters);
    }
}

.htaccess: This is on the same main route as index

             Options -MultiViews          RewriteEngine On

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

    
asked by Gamez 21.06.2017 в 00:29
source

0 answers