Rewrite Question

You can handle rewrites in a plugin or in your theme’s functions.php.

I think something like this might work (assuming attachment_id and attachment_category are registered tags/variables.

<?php 
add_action('init', 'myplugin_rewrite_rule');
function myplugin_rewrite_rule() {

    add_rewrite_rule('^portfolio/([^/]*)/([^/]*)/?$',
        'index.php?attachment_id=$matches[1]&attachment_category=matches[2]',
        'top');
}