I'm going to assume that you want to rewrite http://www.sitename.com/aaa/category/article.html to http://www.sitename.com/aaa/111-category/999-article.html, and that you are using PHP and some form of database for storing the articles (at least the names and IDs)
ModRewirte can't add in extra data (unless it is hard coded values which would apply the same to each url).
You can, however make it do an internal rewrite (not a redirect) for everything to index.php
, then index.php can read the $_SERVER['REQUEST_URI'] to see what URL is requested. This will get you /aaa/category/article.html
which you can then do whatever you want with PHP, including send off a redirect.
The following are extracts from where I performed the same trick, but with a different purpose. The first bit ignores locations such as the css and images folder. Anything which does not match those locations will be sent to index.php
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
RewriteCond %{REQUEST_URI} !/css/.*$
RewriteCond %{REQUEST_URI} !/images/.*$
RewriteCond %{REQUEST_URI} !/js/.*$
RewriteCond %{REQUEST_URI} !/favicon\.ico$
RewriteCond %{REQUEST_URI} !/robots\.txt$
RewriteRule . index.php
and your index.php (or whatever you want to call it: mine is router.php)
<?php
function http_redirect($url, $code=301) {
header('HTTP/1.1 '.$code.' Found');
header('Location: '.$url);
echo 'Redirecting to <a>'.$url.'</a>.';
die('');
}
$loc = explode('?', $_SERVER['REQUEST_URI']); //Get rid of any query string
$query = loc[1];
$loc = explode('/', $loc[0]);
//you now have
//array('aaa','category','article.html')
//look these up in the database to build your new URL
http_redirect('my/new/url'.$loc[0]); //whatever, don't forget the query string if it has 1
?>
You should also add more error checking, I left it out to keep it short