htaccess hide model parameters MVC [duplicate]

4

I have the following URL:

http://192.168.1.67/plays/mvc/index.php?route=profile&user=mikas.28

Where route = PAGE and user = USERNAME.USERID

I have the following htaccess

Options -Multiviews
RewriteEngine On

RewriteBase /plays/mvc

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ index.php?route=$1 [L]

And what I got was:

http://192.168.1.67/plays/mvc/profile&user=mikas.28

It worked to remove index.php?route= , I tried to add other rules that suited to eliminate others but I could not.

My goal is to reach http://192.168.1.67/plays/mvc/profile/mikas.28

If this is achieved I have to change something in my index.php?

$router = new Router();

if(isset($_GET['route'])) {
   $route = $_GET['route'];
}
else {
   $route = 'home';
}


if(!is_null($router->get($route))) {

   $r = $router->get($route);
   $controllerName = $r['controller'];
   $methodName = $r['method'];

   require_once "controllers/" .$controllerName. '.php';
   $controller = new $controllerName();
   $controller->$methodName();

}

else {
   echo "404 Not Found!";
}
    
asked by anonymous 11.09.2015 / 16:03

2 answers

0

I was able to:

htaccess:

RewriteRule ^(.*)$ index.php?route=$1 [L]
RewriteRule ^([^/]+)(/)([^/]+)$ index.php?route=$1&user=$3 [L]

index.php:

$router = new Router();

if(isset($_GET['route'])) {
   $route = $_GET['route'];
   $route = explode("/", $route)[0];
}
else {
   $route = 'home';
}
...
    
11.09.2015 / 17:34
2

The rewriting rule is misspelled. Instead of:

RewriteRule ^(.+)$ index.php?route=$1 [L]

Type:

RewriteRule ^([^/]+)(/)([^/]+)$ index.php?route=$1&user=$3 [L]
    
11.09.2015 / 16:53