user280960
user280960

Reputation: 721

Micro Application Phalcon "/" route redirect to not Not found

I started to learn Phalcon Micro Application and generated the project using phalcon dev tools. I am facing problem for routes.

Below are the codes for .htaccess and my routes, but whenever i go to any other root other than "/" , it works, but for "/" route it goes to not found route.

Default .htaccess

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteRule  ^$ public/    [L]
 RewriteRule  (.*) public/$1 [L]
</IfModule>

Public folder .htaccess

AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>

My routes in public/index.php are:

$app->get('/', function () {
  echo "home";
});

$app->notFound(function(){
  echo "not Found";
});

My project is in vagrant VM with the below url

http://192.168.50.4/api/

Can you please help me

Really Appreciate

Thanks,

Upvotes: 0

Views: 314

Answers (2)

Juri
Juri

Reputation: 1369

Or:

$di->set('url', function () { $url = new Url(); $url->setBaseUri('/api/'); return $url; });

Upvotes: 1

user4341939
user4341939

Reputation:

Nice choice of framework!

Try to change

$app->get('/api', function () {

I sugest you use handlers, an then you cand add a prefix to your application routes, see the documentation below:

https://docs.phalconphp.com/pt/latest/reference/micro.html#using-controllers-as-handlers

Upvotes: 1

Related Questions