We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Issue with Rewrite Rules

Hello! I'm new on PhalconPHP and on programming too...

I read about Phalcon and bought the Cookbook, and seems to be very useful and reliable. I'm using here Windows 10 x64, with XAMPP and have no issues with the command line 'phalcon project myproject' its creating 'myproject' with success.

But when I visit 'myproject' on localhost under 'phalcon' folder, like 'localhost/phalcon/myproject/' I'm geting a issue I think that is about the rewrite rules on apache.

Pressing F12 on Google Chrome I see the reference to 'favicon' wrong, this is giving me to '/phalcon/myproject/img/favicon.ico' and not to '/phalcon/myproject/public/img/favicon.ico' How can I fix that? To get 'myproject' running with no problem as subfolder?

Thanks!



85.5k

ditch the windows server while you are in early stage :D

// download virtual box, ubuntu-server ( there are million tutorails ). While i advice you NOT to do it, cuz it will cause you headaches for few days, you should do it some day...

anyways...

did you do those https://olddocs.phalcon.io/en/3.0.0/reference/apache.html

make sure you restart apache after changing config

I dont understand what these docs apply on my case, because the dev tools generate the .htaccess and htroute for me, and the apache are just whell...I can visite my 'localhost/phalcon/myproject/' just the case of favicon are with issue, and Its a fresh install, and I did really not understand why.

I have tried, and get the same issue...



43.9k
edited May '18

Hi

you have created a phalcon project with the devtools => phalcon framework extension is loaded because the devtools themselve are using phalcon !!!

So, phalcon is up and running, a phpinfo() should confirm that.

Your problem could come from

  • a bad apache configuration regarding rewrite rules (see here: https://docs.phalcon.io/en/3.3/webserver-setup#apache)
  • or bad staticBaseUri definition (wich is not set by default after an app creation with the devtools), in config.php, after 'baseUri' => ...., try with 'staticBaseUri' => '/phalcon/myproject/',

and in config/service.php


$di->setShared('url', function () {
    $config = $this->getConfig();
    $url = new UrlResolver();
    $url->setBaseUri($config->application->baseUri);
    $url->setStaticBaseUri($config->application->staticBaseUri);
    return $url;
});

I dont understand what these docs apply on my case, because the dev tools generate the .htaccess and htroute for me, and the apache are just whell...I can visite my 'localhost/phalcon/myproject/' just the case of favicon are with issue, and Its a fresh install, and I did really not understand why.

Thansk for the atention! I have do that configuration like on docs and add this staticBaseUri like you said, and nothing changes the favicon path error.

I see on the /phalcon/myproject/app/views/index.phtml that code:

href="<?php echo $this->url->get('img/favicon.ico')?>"

I understand that If I change that to:

href="<?php echo $this->url->get('public/img/favicon.ico')?>"

This issue will be solved, but is not the correct way, because I think the devtools generate the index.phtml correctly, right? Something else is wrong here.

Hi

you have created a phalcon project with the devtools => phalcon framework extension is loaded because the devtools themselve are using phalcon !!!

So, phalcon is up and running, a phpinfo() should confirm that.

Your problem could come from

  • a bad apache configuration regarding rewrite rules (see here: https://docs.phalcon.io/en/3.3/webserver-setup#apache)
  • or bad staticBaseUri definition (wich is not set by default after an app creation with the devtools), in config.php, after 'baseUri' => ...., try with 'staticBaseUri' => '/phalcon/myproject/',

and in config/service.php


$di->setShared('url', function () {
   $config = $this->getConfig();
   $url = new UrlResolver();
   $url->setBaseUri($config->application->baseUri);
   $url->setStaticBaseUri($config->application->staticBaseUri);
   return $url;
});

I dont understand what these docs apply on my case, because the dev tools generate the .htaccess and htroute for me, and the apache are just whell...I can visite my 'localhost/phalcon/myproject/' just the case of favicon are with issue, and Its a fresh install, and I did really not understand why.



43.9k

This issue will be solved, but is not the correct way, because I think the devtools generate the index.phtml correctly, right? Something else is wrong he

you are right.

Pressing F12 on Google Chrome I see the reference to 'favicon' wrong, this is giving me to '/phalcon/myproject/img/favicon.ico'

no, this is the correct !


echo Phalcon\Tag::image("img/bg.png");

// does this work (assuming that there is an existing image bg.png file in myproject/public/img/ folder)