WhatIsOpenID
WhatIsOpenID

Reputation: 1101

Help me write a Regex RewriteRule for htaccess

I need help writing a simple regex for RewriteRule for mod_rewrite in htaccess. So, here is what I am trying to accomplish:

books/2010-the-world-by-hopkins-139_PPS-1234567

should go to

index.php?pagename=mypage&PPS=1234567&description=2010-the-world-by-hopkins-139

So, in pseducode, the regex has to split the part after books by _ and I should get it into two parts:

  1. PPS (it is always a numeric with 1+ variable number of digits). This is the part after _PPS-
  2. Description (it is always a string). This is the part containing ANYTHING before the _.

I guess the RewriteRule will be something like:

RewriteRule books/(.*)_(.*) index.php?pagename=mypage&PPS=$2&description=$1

But I need correct regex. Plese help.

Upvotes: 0

Views: 214

Answers (1)

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

something like: but flip the $1 and $2 ;)

^books/(.*)_PPS-([0-9]{1,})$

Upvotes: 1

Related Questions