Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Wierd router issue

I have something strange happening. Didn't notice it before.

When I use <a href=""> in my view files the url is as it should be eg: http://site.ext/backend/users or http://site.ext/backend/login

But when I use a redirect within a controller then 'public' is added to the path. Anyone have an idea how to prevent the public from appearing when using a redirect?

  return $this->response->redirect( 'backend' );

This should redirect me to http://site.ext/backend/ but instead it redirects me to http://site.ext/public/backend/ instead. I do not recall having this issue with other phalcon projects.

The site is running on a vagrant vm in a virtualbox environment, with apache and php-fpm. The used .htaccess files are as follows:

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


AddDefaultCharset UTF-8

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]

Phalcon version 3.3.2 running on php 7.2

php -i

Web framework delivered as a C-extension for PHP
phalcon => enabled
Author => Phalcon Team and contributors
Version => 3.3.2
Build Date => Mar 10 2018 14:53:32
Powered by Zephir => Version 0.10.7-2917ebe8ae

Directive => Local Value => Master Value
phalcon.db.escape_identifiers => On => On
phalcon.db.force_casting => Off => Off
phalcon.orm.cast_on_hydrate => Off => Off
phalcon.orm.column_renaming => On => On
phalcon.orm.disable_assign_setters => Off => Off
phalcon.orm.enable_implicit_joins => On => On
phalcon.orm.enable_literals => On => On => On => On
phalcon.orm.exception_on_failed_save => Off => Off
phalcon.orm.ignore_unknown_columns => Off => Off
phalcon.orm.late_state_binding => Off => Off
phalcon.orm.not_null_validations => On => On
phalcon.orm.update_snapshot_on_save => On => On
phalcon.orm.virtual_foreign_keys => On => On

edited May '18

Seems I found a solution to my issue. Placing this in the depencency injector solves my problem.

      // Set-up url
      $di->set( 'url', function()
        return (new Url())
          ->setBaseUri( "/" );

Always set base URI using setBaseUri.

I always put that value in a config object: