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

phalcon tutorial question -> https://phalcon-php-framework-documentation.readthedocs.io/en/1.2.0/reference/tutorial.html

Hi there

On https://phalcon-php-framework-documentation.readthedocs.io/en/1.2.0/reference/tutorial.html , they write i have to place a .htaccess file on /:

"Let’s create a couple of rewrite rules in the /.htaccess file:"

...its content should be:

/.htaccess

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

...BUT: The direcory structure is as follows:

tutorial/
  app/
    controllers/
    models/
    views/
  public/
    css/
    img/
    js/

So there can't be the entries RewriteRule ^$ public/ [L] and RewriteRule (.*) public/$1 [L], because there is NO/public folder on webserver root path... the public folider is /tutorial/public on NOT /public

That does match in my opinion...(?)

(Maybe i'm wrong, but i don't think!!)

Thank you for your feedbacks! :-)

With best regards, Jan

I also don't unterstand the 2nd .htaccess rule set, with its header comment /public/.htaccess

There is also NO folder /public, the folder with the "public" directory is on /tutorials/public ...



125.7k
Accepted
answer
edited Oct '19

FYI - your post was really hard to read so I modified it. Please take a look - just to see how formatting works.

Those tutorials are ancient. They're for 1.2.0, and the current production release is 3.4 (4.0 soon). I'd recommend looking at updated tutorials: https://docs.phalcon.io/3.4/en/tutorial-base

With that said - the part you're asking about is .htaccess, which I don't think has changed much, if at all. So, with that said...

The rule, very critically is for public/, not /public. Since the .htaccess file lives in /tutorial, a reference to public/ - being a relative reference - points to /tutorial/public. That rule is basically saying "All traffic gets re-routed to public/[whatever was requested].

You'll then have another .htaccess file in public/ that says "if the request isn't for an actual file, route the request to index.php".

The combination of those two .htaccess files results in only files in public/ being able to be accessed directly (ie: css, js, images). Anything else is assumed to be a route, and is passed to index.php for processing and routing.

Hello Dylan

Now it works, thank you very much!

With best regards, Jan