Skip to content

Instantly share code, notes, and snippets.

@jamesvl
Created April 8, 2011 17:32

Revisions

  1. jamesvl revised this gist Apr 14, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowov
    If you're trying to route requests for an app that is *not* in the document root, invoke klein's dispatch line like this:

    <?php
    define('APP_PATH', '/webapps/criminal/crim_daily_calendar');
    define('APP_PATH', '/your/webapp');
    dispatch(substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));
    ?>

  2. jamesvl revised this gist Apr 14, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -19,8 +19,8 @@ Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowov
    If you're trying to route requests for an app that is *not* in the document root, invoke klein's dispatch line like this:

    <?php
    define('APP_PATH', '/webapps/criminal/crim_daily_calendar');
    dispatch(substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));
    define('APP_PATH', '/webapps/criminal/crim_daily_calendar');
    dispatch(substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));
    ?>

    Then in your `nginx.conf` file, use:
  3. jamesvl revised this gist Apr 14, 2011. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    ## URL-rewriting for klein PHP router

    Why rewrite URLs? Read this: http://en.wikipedia.org/wiki/Rewrite_engine
    Why rewrite URLs? Check [Wikipedia](http://en.wikipedia.org/wiki/Rewrite_engine)

    ### Apache

    Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride) is on for the directory, or put in `httpd.conf`
    Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride) is on for your directory, or put in `httpd.conf`

    # Apache (.htaccess or httpd.conf)
    RewriteEngine On
    @@ -13,33 +13,35 @@ Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowov

    ### nginx

    # basic version
    # basics
    try_files $uri $uri/ /index.php?$args;

    If you're trying to route requests for an app that is *not* in the document root, you can do so. You have to invoke klein's dispatch line like this though:
    If you're trying to route requests for an app that is *not* in the document root, invoke klein's dispatch line like this:

    <?php
    define('APP_PATH', '/webapps/criminal/crim_daily_calendar');
    dispatch(substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));
    ?>

    In your `nginx.conf` file, use:
    Then in your `nginx.conf` file, use:

    location /your/webapp/ {
    try_files $uri $uri/ /your/webapp/index.php?$args;
    }

    Don't do this. See [nginx pitfalls](http://wiki.nginx.org/Pitfalls).
    **Don't** do this.

    # nginx
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }

    See [nginx pitfalls](http://wiki.nginx.org/Pitfalls).

    ## More Reading
    * http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
    * http://wiki.nginx.org/HttpRewriteModule
    * http://wiki.nginx.org/Pitfalls
    * [klein.php](https://github.com/chriso/klein.php) - simple, fast router for PHP

    Note: This gist [originally here](https://gist.github.com/874000), from [chriso](https://github.com/chriso)
    Note: This gist originally [here](https://gist.github.com/874000), from [chriso](https://github.com/chriso)
  4. jamesvl revised this gist Apr 14, 2011. 2 changed files with 45 additions and 19 deletions.
    45 changes: 45 additions & 0 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    ## URL-rewriting for klein PHP router

    Why rewrite URLs? Read this: http://en.wikipedia.org/wiki/Rewrite_engine

    ### Apache

    Make sure [AllowOverride](http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride) is on for the directory, or put in `httpd.conf`

    # Apache (.htaccess or httpd.conf)
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . /index.php [L]

    ### nginx

    # basic version
    try_files $uri $uri/ /index.php?$args;

    If you're trying to route requests for an app that is *not* in the document root, you can do so. You have to invoke klein's dispatch line like this though:

    <?php
    define('APP_PATH', '/webapps/criminal/crim_daily_calendar');
    dispatch(substr($_SERVER['REQUEST_URI'], strlen(APP_PATH)));
    ?>

    In your `nginx.conf` file, use:

    location /your/webapp/ {
    try_files $uri $uri/ /your/webapp/index.php?$args;
    }

    Don't do this. See [nginx pitfalls](http://wiki.nginx.org/Pitfalls).

    # nginx
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }

    ## More Reading
    * http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
    * http://wiki.nginx.org/HttpRewriteModule
    * http://wiki.nginx.org/Pitfalls
    * [klein.php](https://github.com/chriso/klein.php) - simple, fast router for PHP

    Note: This gist [originally here](https://gist.github.com/874000), from [chriso](https://github.com/chriso)
    19 changes: 0 additions & 19 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,19 +0,0 @@
    # Apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]

    # nginx
    # bad - see http://wiki.nginx.org/Pitfalls
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }

    # basic version
    try_files $uri $uri/ /index.php?$args;

    # if running klein from a subdirectory
    location /your/webapp/ {
    try_files $uri $uri/ /your/webapp/index.php?$args;
    }
  5. jamesvl revised this gist Apr 14, 2011. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,10 @@ if (!-e $request_filename) {
    rewrite . /index.php last;
    }

    # better
    try_files $uri $uri/ /index.php;
    # basic version
    try_files $uri $uri/ /index.php?$args;

    # better still, for our purposes (remove '/' if in a location block?)
    try_files $uri /index.php;
    # if running klein from a subdirectory
    location /your/webapp/ {
    try_files $uri $uri/ /your/webapp/index.php?$args;
    }
  6. jamesvl revised this gist Apr 8, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # Apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]

    # nginx
    # bad - see http://wiki.nginx.org/Pitfalls
  7. jamesvl revised this gist Apr 8, 2011. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    # Apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]

    # nginx
    # bad - see http://wiki.nginx.org/Pitfalls
  8. jamesvl revised this gist Apr 8, 2011. 1 changed file with 9 additions and 2 deletions.
    11 changes: 9 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,14 @@ RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]

    # NGINX
    # nginx
    # bad - see http://wiki.nginx.org/Pitfalls
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }
    }

    # better
    try_files $uri $uri/ /index.php;

    # better still, for our purposes (remove '/' if in a location block?)
    try_files $uri /index.php;
  9. jamesvl revised this gist Apr 8, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule . index.php [L]

    # NGINX
    if (!-e $request_filename) {
  10. jamesvl revised this gist Apr 8, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    # Apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    # NGINX
  11. @chriso chriso revised this gist Apr 7, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    /* Apache */
    # Apache
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteRule . /index.php [L]

    /* NGINX */
    # NGINX
    if (!-e $request_filename) {
    rewrite . /index.php last;
    }
  12. @chriso chriso revised this gist Apr 7, 2011. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,10 @@
    /* Apache */
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteRule . /index.php [L]

    /* NGINX */
    if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php last;
    rewrite . /index.php last;
    }
  13. @chriso chriso created this gist Mar 17, 2011.
    11 changes: 11 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    /* Apache */
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME}!-f
    RewriteCond %{REQUEST_FILENAME}!-d
    RewriteRule . /index.php [L]

    /* NGINX */
    if (!-e $request_filename) {
    rewrite ^(.+)$ /index.php last;
    }