Why is Zenphoto using a custom rewrite engine?

Once upon a time, old version of Zenphoto used a standard .htaccess file to manage page URL rewriting and redirects.

After updating my instance of Zenphoto, all of the URL rewriting is carried out by rewrite.php, with the rules defined in the zenphoto-rewrite.txt file.

On my Zenphoto instances I used to use a lot of custom .htaccess rules to make custom pages work. With the change to how rewriting works, these are now broken, and I'm trying to get my head around the new engine.

I'm curious as to the reason for the change in the rewriting engine - I'm assuming there were some benefits to it, otherwise it would never have been done.

Comments

  • wongm Member
    I've finally started to get my head around the new rewrite engine - it appears that the main benefit is the logic that builds up the clean' URLs on each page uses the same logic as the rewrite rule definitions used for incoming requests, so there is no need to duplicate the logic in two places.

    Now I just need to rewrite my old code to use the same patterns. :-D
  • acrylian Administrator, Developer
    Exactly. And the other main benefit is that you can re-define parts of the urls yourself using the rewriteTokens plugin. Not the general structure of course but for example if you don't like the default "news" keyword in the Zenpage news articles url you can change it to "blog" or a term in another language. Without editing .htaccess which is in danger to be overwritten on an update.
  • The other benefit is that these rules work with any system that can manage to redirect to the root index.php script. So for instance they work with nginx with simple nginx rewrite server block. Especially good since typically installations cannot make modifications to this server block.

    Of course you really could continue to use your old code. Any "query" link or link to something other than index.php will still work. You just don't need the old Zenphoto code (but it will not hurt to leave it.)

    It is relatively straight forward to add rules via plugins. Here is a simple plugin to create a "stand-alone" link to a custom page:

    `<?php

    /* Rredirects "MyPage"
    *
    * @package plugins
    * @subpackage MyPage
    */
    $plugin_is_filter = 5 | CLASS_PLUGIN;
    $plugin_description = gettext('Redirect link');
    $plugin_author = "Stephen Billard (sbillard)";
    $plugin_version = '1.4.5';

    $_zp_conf_vars['special_pages']['MyPage'] = array('define' => false, 'rewrite' => 'MyPage', 'rule' => '^%REWRITE%/*$ index.php?p=pages&title=MyPage[L,QSA]');
    ?>

    More complex examples may be found in the zenphoto plugins that make special links. E.g. the `favoritesHandler` and even (most complex) the `zenpage` plugin.
Sign In or Register to comment.