Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I use something similar to his /index.php solution and it has worked great for me. My .htaccess ends with:

    ### Disable direct access to *.php except main index.php
    RewriteCond %{REQUEST_URI} \.php
    RewriteCond %{REQUEST_URI} !^/index.php
      RewriteRule ^(.*)$ /index.php [L,R]

    ### Run the main /index.php controller file
    RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^(.*)$ /index.php [L]
In my index.php, I include my common functions and then call the appropriate file/class depending on the hostname and url. I don't know why he dirties with index.php call with: path=$1&%{QUERY_STIRNG} - that information is available in $_SERVER[] variable.

What this overall approach really means is that there is a single entry point for every single thing in my app. I can manage sessions, db, custom functions, login/admin, handle apis etc. through one piece of code that is (selectively) executed for every single request. I can also shutdown the entire site and all the operations with a "sorry we're down for maintenance" if I need to. I don't even store my php files in /www folder so you can't even access them directly. This approach can easily handle my traffic - 10k uniques/day on average, 100k/day on special events.



Consider applying for YC's Winter 2027 batch! Applications are open till November 2.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: