Take mod_rewrite for Apache server.
I don’t fully understand why do I need both RewriteRules in this sample:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Originally found at this DIY MVC tutorial, it seems like ^$ and (.*) mean the same thing. And why do I need two [L]ast flags since the second is not supposed to fire, right?
I’m trying to deeper understand all the internal mechanics instead of just copying the working solution.
No,
^$and.*don’t mean the same thing: the first matches only an empty input, the second will match anything — including an empty input. The second rule should be enough.As to why there is
[L]here, consider an empty request, and no[L]:public/;public/intopublic/public/.