[thelist] mod rewriting question

Stephen Rider evolt_org at striderweb.com
Tue May 15 14:54:41 CDT 2007


On May 15, 2007, at 2:35 PM, Tom Dell'Aringa wrote:

> On 5/15/07, Stephen Rider <evolt_org at striderweb.com> wrote:
>
> My corrected version would be:
> RewriteRule ^[0-9]{4}/[0-9]{2}/[0-9]{2}/(.+?)/?$ /articles/$1/  
> [R=301,L]
>
> Now we're getting somewhere - that seems to work for most articles.  
> It doesn't seem to work for articles that begin with a number, I  
> assume the $1 doesn't take that into account? (IIRC $1 is some kind  
> of rule shortcut?) Can we modify it to accept a url like this:
>
> /2006/07/28/10-claims-in-the-bible-on-the-deity-of-christ/
>
> so it goes to
>
> /articles/10-claims-in-the-bible-on-the-deity-of-christ/

Hmm...

In grep, you use parentheses to capture strings for later use.  $n  
returns whatever string was captured by the nth set of parens.  Thus,  
$1 should return whatever is captured by the first set of parentheses.

I can't see why it wouldn't work for something beginning with a  
number, but mod_rewrite is pretty much voodoo -- a lot of trial and  
error.

Try misterhaan's version and see if that does better:

RewriteRule ^[0-9]{4}(/[0-9]{2}){2}/([^/]+)/?$ /articles/$2/ [R=301,L]

Otherwise, try experimenting.  My best guess is that somehow the  
number beginning the article name was tripping the [0-9] part of the  
RegEx, but I'm not sure how, since we should have been past that  
point...

Steve


More information about the thelist mailing list