Category Archives: altorouter

htaccess file subdomain pointing index.php

There's a lot of questions out there related to .htaccess but that just got me more confused with the problem that I'm facing. I have a subdomain (app.example.com) and I want to point out the application to use the index.php only for this subdomain. I'm also using AltoRouter and followed the instructions written in the documentation, but I get a 500 error when I put it up on the server. Here is my .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

I assumed placing these rules in the subdomain folder would make it work but it just doesn't want to. Right now these rules are in the app folder (in the subdomain). Any idea what I'm doing wrong?

Thanks in advance!

htaccess file subdomain pointing index.php

There's a lot of questions out there related to .htaccess but that just got me more confused with the problem that I'm facing. I have a subdomain (app.example.com) and I want to point out the application to use the index.php only for this subdomain. I'm also using AltoRouter and followed the instructions written in the documentation, but I get a 500 error when I put it up on the server. Here is my .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

I assumed placing these rules in the subdomain folder would make it work but it just doesn't want to. Right now these rules are in the app folder (in the subdomain). Any idea what I'm doing wrong?

Thanks in advance!

alto router does’t route correctly

i've made the .htaccess file and that works, but the routing of alto router doesn't

<?php

require 'altorouter.php';

$router = new AltoRouter();
$router->setBasePath('/rimaxxApi/');
$router->map('GET', '/', function(){

  echo 'It is working';
});

$match = $router->match();

// Here comes the new part, taken straight from the docs:

// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] );
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}

?>

The path is in a subfolder

With this code i keep getting the "404" error, but i have the route defined.

alto router does’t route correctly

i've made the .htaccess file and that works, but the routing of alto router doesn't

<?php

require 'altorouter.php';

$router = new AltoRouter();
$router->setBasePath('/rimaxxApi/');
$router->map('GET', '/', function(){

  echo 'It is working';
});

$match = $router->match();

// Here comes the new part, taken straight from the docs:

// call closure or throw 404 status
if( $match && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['target'], $match['params'] );
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}

?>

The path is in a subfolder

With this code i keep getting the "404" error, but i have the route defined.

How I can have the URL look like this with altorouter?

I have two PHP files, index.php and another file call upload.php I'm trying to use altorouter for have in URL in index.php only www.myurl.com/index and not www.myurl.com/ or /index.php when I click the button in index.php of the form now the URL is www.myurl.com/upload.php I want only www.myurl.com/upload, I'm trying to use altorouter I set the htaccess like this

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

And in another script call routes.php I'm trying to mapping URL in this mode

<?php
$router = new AltoRouter();

// map homepage
$router->map( 'GET|POST','/', function() {
    require __DIR__ . '/index.php';
});

// map user details page
$router->map( 'GET|POST', '/upload/', function() {
    require __DIR__ . '/upload.php';
});
?>

In index.php I write this for matching

include "include/routes.php";

$match = $router->match();
var_dump ($match);

When I print match value with var_dump the results is

array(3) { ["target"]=> object(Closure)#4 (0) { } ["params"]=> array(0) { } ["name"]=> NULL }

I have to include tha matching in upload.php or no? And here the URL is ever / I want /index, what's wrong?

Empty GET to AltoRouter

I'm trying to use AltoRouter, but I'm trying to follow its documentation and my problem is that $_GET always to be empty.

I'm using Apache, and my .htaccess is like the following:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

And now this is my file to take the $_GET and make the router:

$router->map('GET', '/', '[email protected]', 'home');
$match = $router->match();

list($controller, $method) = explode("@", $match['target']);

if(is_callable(array($controller, $method))) {
  $object = new $controller();
  call_user_func_array(array($object, $method), array($match['params']));
} else {
  echo "Cannot find $controller -> $method";
  exit();
}

But I see that it ins't work, because when I'm receiving the $_GET, it's always empty, I used a print_r($_GET) to see within to $_GET, but was returned to me a array empty.

I tried with the followings URL's, but the result was the same:

http://localhost/mvc/
http://localhost/mvc/page
http://localhost/mvc/controller
http://localhost/mvc/produto/cadastrar