in Technology

Small Mantis hack

SmallCo – one of our clients – wanted to customize Mantis a little bit. Essentially, they wanted to give project specific URLs to users. So when the user logs in, he will automatically be redirected to that project’s bug page. The user may be working on multiple projects, but a project specific URL will jump him directly to the one he wants to work on now.

I thought I would have to tweak some Mantis code to get this working. I even started writing a PHP page that would detect the project name from the URL and put in appropriate “return” value in the login_page.php. Then I thought it was not necessary to put the project name in the URL. It would be shorter, better and faster to just use the project_id. And in that case, I don’t even need a PHP page. I can do it with mod_rewrite.

So here goes, a quick .htaccess snippet that will redirect the user to a project specific bug page after logging in. This works only if the user is not logged in. After logging in, he can use the project switcher drop down at the top right.


<ifmodule mod_rewrite.c>
RewriteEngine on
RewriteBase /~nirav/mantis/
RewriteRule ^project/(.*)$ login_page.php?return=set_project.php?project_id=$1 [R,L]
</ifmodule>

I had Mantis installed at http://servername/~nirav/mantis/. So when I access it as http://servername/~nirav/mantis/project/1 – it would take me to project_id 1 after logging in. You wouldn’t need the RewriteBase part in most cases, I needed it because we had user directories feature on.


Write a Comment

Comment

  • Related Content by Tag