Short URLs for Tickets and Queues

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 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

RewriteEngine on

`The great thing about mod_rewrite is it gives you all the configurability
and flexibility of Sendmail. The downside to mod_rewrite is that it gives
you all the configurability and flexibility of Sendmail.‘’
– Brian Behlendorf Apache Group

Treat a single number as a ticket number:

RewriteRule ^/([0-9]+)$ /Ticket/Display.html?id=$1

Remember to finish processing the request, with ‘last rule’ afterwards,
eg:

RewriteRule ^/([0-9]+)$ /Ticket/Display.html?id=$1 [L]

Treat anything else that doesn’t look like a file or directory as a

queue name:

RewriteRule ^/([^/.]+)$ /Search/Listing.html?ShowQueue=$1

RewriteRule ^/([^/.]+)$ /Search/Listing.html?ShowQueue=$1 [L]

Regards,

                         Bruce Campbell                            RIPE
               Systems/Network Engineer                             NCC
             www.ripe.net - PGP562C8B1B                      Operations

Bruce Campbell wrote:> On Tue, 9 Apr 2002, Smylers wrote:

RewriteRule ^/([0-9]+)$ /Ticket/Display.html?id=$1

Remember to finish processing the request, with ‘last rule’ afterwards,
eg:

RewriteRule ^/([0-9]+)$ /Ticket/Display.html?id=$1 [L]
RewriteRule ^/([^/.]+)$ /Search/Listing.html?ShowQueue=$1 [L]

I had those "[L]"s in originally, then I took them out when I realized
they weren’t doing anything – the rules have to be in the order they
are so that ticket numbers don’t get caught as queue names initially.
But once a ticket number has been rewritten to the full
/Ticket/Display.html URL, it’s got a slash in it so won’t match the
second rule anyway.

So I don’t think it makes a lot of difference either way. In theory
it’s better to leave them out, as it means that any further rewriting
that somebody was doing to an explicit ticket or search URL will still
happen to a shortcut-rewritten URL …

Cheers.

Smylers
GBdirect

Smylers:

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

What a great idea; simple, but effective. Thanks.

“I don’t think so,” said Rene Descartes. Just then, he vanished.

That’s quite cute. I’ve wanted something like that for a while :wink:
One other way that this could be implemented is using a mason
dhandler. Which I should really do for 2.2 :wink:

-jOn Tue, Apr 09, 2002 at 10:36:50PM +0100, Simon Cozens wrote:

Smylers:

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

What a great idea; simple, but effective. Thanks.


“I don’t think so,” said Rene Descartes. Just then, he vanished.


rt-users mailing list
rt-users@lists.fsck.com
http://lists.fsck.com/mailman/listinfo/rt-users

http://www.bestpractical.com/products/rt – Trouble Ticketing. Free.

Yesterday Jesse Vincent wrote:

That’s quite cute. I’ve wanted something like that for a while :wink:

Ta (and to Simon).

One other way that this could be implemented is using a mason
dhandler. Which I should really do for 2.2 :wink:

Yes, it’d be better for it not to be ‘Apache’-dependent.

Also the punctuation characters (so people don’t have to remember
whether to use spaces, hyphens or underscores) could probably be dealt
with in a safer way, possibly along these lines:

if (there_is_a_queue_called_exactly $queue_requested)
{
$queue_to_use = that_queue;
}
else
{
($queue_requested, @all_queue_names)
= map { tr/a-z0-9//cd; lc; } ($queue_requested, @all_queue_names);
foreach my $queue (@all_queue_names)
{
if ($queue eq $queue_requested)
{
$queue_to_use = $queue;
last;
}
}

if (!$queue_to_use)
{
  foreach my $queue (@all_queue_names)
  {
    if ($queue =~ /^$queue_requested/o)
    {
      $queue_to_use = $queue;
      last;
    }
  }
}

}

Oooh, that looks like it even copes with unique prefixes!

Smylers
GBdirect

Yesterday Jesse Vincent wrote:

That’s quite cute. I’ve wanted something like that for a while :wink:

Smylers,

While that was really a good one, I realized that by incorporating it
I could not get to my stats page because that is assumed to be the name
of a queue, yes? http://rt-URL/Stats doesn’t work like it used to before,
so I have to go ahead and type http://rt-URL/Stats/CallsQueueDay.html
Hmm, cramming that would be an issue with other RT users, right?

And while on this, though OT, how can one delete a ticket from the RT interface?

Thanks to all.

-Wash

Odhiambo Washington wash@wananchi.com “The box said ‘Requires
Wananchi Online Ltd. www.wananchi.com Windows 95, NT, or better,’
Tel: 254 2 313985-9 Fax: 254 2 313922 so I installed FreeBSD.”
GSM: 254 72 743 223 GSM: 254 733 744 121 This sig is McQ! :slight_smile:
“I was playing poker the other night … with Tarot cards. I got a full
house and four people died.”
– Steven Wright

Odhiambo Washington wrote:

While that was really a good one, I realized that by incorporating it
I could not get to my stats page because that is assumed to be the
name of a queue, yes?

Stats is an add-on that I don’t use, I’m afraid – I did check that all
of the standard ‘RT’ URLs contain a slash or a dot.

http://rt-URL/Stats doesn’t work like it used to before,
so I have to go ahead and type http://rt-URL/Stats/CallsQueueDay.html

Without knowing anything about the stats package, I’m gussing that it
might work if you put a slash on the end, like so:

http://rt-URL/Stats/

If Stats is a directory, then a URL with it as the final part must end
in a slash. Most web servers are set up so that if a user misses out
the slash they will rewrite the URL to have a slash in, then return the
en-slashed URL to the browser in the Location: header (and the browser
can then request the content from the correct URL – yes it has to be
done with two separate requests like this just because somebody didn’t
type a slash).

But my queue name rewriting rule is obviously coming into affect before
your server’s slash-adding rule. Among other ways of solving this, you
could put a RewriteCond in there that checks for $1 not being found on
the disk and only rewriting otherwise.

There is another problem with my code that will affect all users though.
There are links on both the search results (first, next, prev) and
ticket display (full headers, reply, comment) which are relative to the
current page. For example links that think they are in the /Ticket/
directory aren’t, because the short URL doesn’t have that in there.

It isn’t too difficult to tweak the files to use absolute URLs, thereby
fixing this.

Smylers
GBdirect

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

… Search/Listing.html has to be modified to know what to do with a
ShowQueue parameter and turn it into the usual kind of queue search
… 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’,

That of course is completely pointless. I generated this hash by
pasting in a ‘proper’ URL then doing search and replace on ampersand and
equals characters. Instead of overwriting a hash entry that’s only just
been created, we actually want an array in there. Replace the above two
lines with:

    ValueOfStatus => ['open', 'new'];
    StatusOp => '=',
    QueueOp => '=',
    NewSearch => '1',
  );
}

}

Many apologies for such stupidity.

Smylers

Odhiambo Washington wrote:

While that was really a good one, I realized that by incorporating it
I could not get to my stats page because that is assumed to be the
name of a queue, yes?

Stats is an add-on that I don’t use, I’m afraid – I did check that all
of the standard ‘RT’ URLs contain a slash or a dot.

http://rt-URL/Stats doesn’t work like it used to before,
so I have to go ahead and type http://rt-URL/Stats/CallsQueueDay.html

Without knowing anything about the stats package, I’m gussing that it
might work if you put a slash on the end, like so:

http://rt-URL/Stats/

That solved it - the trailing /

Thanks.

-Wash

Odhiambo Washington wash@wananchi.com “The box said ‘Requires
Wananchi Online Ltd. www.wananchi.com Windows 95, NT, or better,’
Tel: 254 2 313985-9 Fax: 254 2 313922 so I installed FreeBSD.”
GSM: 254 72 743 223 GSM: 254 733 744 121 This sig is McQ! :slight_smile:
Washington [D.C.] is a city of Southern efficiency and Northern charm.
– John F. Kennedy