[rt-users] Short URLs for Tickets and Queues

Smylers smylers at gbdirect.co.uk
Tue Apr 9 10:46:47 EDT 2002


I've just configured this system to use short URLs for displaying
particular tickets or queues, which is handy when typing them manually.

For example this URL displays the ticket 123:

  http://rt-server/123

and this one does a search for all new and open tickets in the
documentation queue:

  http://rt-server/documentation

Having got it working, I thought I'd mention it here in case anybody
else would find it useful.

I've made this work for 'Apache', using mod_rewrite.  It makes a few
assumptions:

  * 'RT' is installed in its own virtual host (though this would be easy
    to alter to your situation).

  * No queue names are entirely numeric.

  * No queue names contain slashes (/) or dots (.).

  * There are no URLs normally served by 'RT' other than the homepage
    that don't contain at least a dot or a slash (for a file extension
    or a directory name).

  * No queue names contain hyphens (-) or underscores (_) (though this
    is just for convenience, so that they can be typed in URLs instead
    of spaces; if this makes life less convenient for you, then
    obviously don't do it!).

The ticket number stuff is easy.  The queue names is slightly harder,
and involves adding some code to 'RT' as well as the 'Apache' config.

These are the lines you need to add to the <VirtualHost> section of
httpd.conf:

  RewriteEngine on

  # Treat a single number as a ticket number:
  RewriteRule ^/([0-9]+)$ /Ticket/Display.html?id=$1

  # Treat anything else that doesn't look like a file or directory as a
  # queue name:
  RewriteRule ^/([^/.]+)$ /Search/Listing.html?ShowQueue=$1

To make that last bit work, Search/Listing.html has to be modified to
know what to do with a ShowQueue paramater and turn it into the usual
kind of queue search (which uses numbers rather than names).  Add this
code at the start of the <%INIT> block in that file:

  if (my $QueueName = $ARGS{ShowQueue})
  {
    $QueueName =~ tr/-_/  /;
    my $Queue = RT::Queue->new($session{CurrentUser});
    if ($Queue->Load($QueueName))
    {
      %ARGS =
      (
        ValueOfQueue => $Queue->Id,
        ValueOfStatus => 'open',
        ValueOfStatus => 'new',
        StatusOp => '=',
        QueueOp => '=',
        NewSearch => '1',
      );
    }
  }

Cheers.

Smylers
-- 
GBdirect
http://www.gbdirect.co.uk/





More information about the rt-users mailing list