« Future-Proofing Slapnose | Main | Mod Rewritten »

March 30, 2004
Mod Rewrite Help

Alright then, here are the things I need mod_rewrite to do... I don't have time today to learn it, yet it consumes my thoughts, so maybe someone with better regex mojo than me can whip these up. There are probably more cases, but this is what I've thought of as likely..

slapnose.com/blogarchives/2004/03/000331.html --> /archives/2004/03/
slapnose.com/blogarchives/2004_09.html --> /archives/2004/09/
slapnose.com/blogarchives/2004_09.html#xxxxxx --> /archives/2004/09/

(Ideally these just point to the directory, as above, but index.html could be appended if necessary)

So, basically, if a link points to an old individual archive (1st example), it should just go to that month's monthly archive. This won't get the specific post, but it's close enough (unless someone can think of a way to get to the individual post). The second example would be a link to an old monthly archive, and the third to an old PermaLink (a monthly archive with an entry ID anchor).

Everything is now under /archives and then Year/Month/Day, but we can ignore the day level for this purpose.

So how about it, smarties? A challenge is issued! A shiny new goat to whosoever can provide the solution.

Comments

Previous Comments

in httpd.conf, turn on rewrite

then start writin your rules:

RewriteRule ^oldstuff\.html newstuff.html

So:

RewriteRule ^blogarchives/2004/03/000331\.html /archives/2004/03/

forgot the $, doh!

RewriteRule ^oldstuff\.html$ newstuff.html

Yeah, that's straightforward enough, but I'd have to do it like 350 times, for each individual entry.. it would take me weeks to look them all up and find the corresponding entry.

There's gotta be a way to take the referrer and rewrite it based on what was in the request, for example 2003_09.html would be rewritten to 2003/09/index.html, but generically, so the same rule would work on 2002_11.html, etc.

ah yes, i see now. hrm, guess you want real answers about regex then, not "sassy-pants" answers...

Sassy-pants answers are welcome too, but they won't get you that goat.

I also approve this message.

ewwwwww.. you got proprietary on me. get it off, get it off!

Alright tonks. I don't have time right now to do the whole thingee ma bob. But a pointer might get you headin the right way.

You can refer to previous patterns by grouping them in parentheses and referring to them with $1, $2, etc.

so if you have a pattern ^([a-z]+)([0-9]+)$ I can refer to whatever was matched in the parentheses as $1 and $2. eg: bubba123 -> $1 = bubba, $2 = 123

for you:

RewriteRule ^blogarchives/([0-9]+)/([0-9]+)/([0-9]+)\.html /archives/$1/$2/

That might even work.

heck, the other one might work like this:

RewriteRule ^blogarchives/([0-9]+)_([0-9]+)\.html /archives/$1/$2/

I'm not gonna test these. No siree. Hope that helps.