views:

18

answers:

1

Can anyone tell me how to do this? i'm stumped!

I need a modified URL in this format

this55-is-a-test-id-23.html

But I need the 23 as a GET. I can't rely on searching for 'id' as this may occur elsewhere in the URL. Is there any way of searching for the last occurrence of id and passing that as a get using an Apache RewriteRule in .htaccess??

Many thanks

Ant

A: 

I'm not able to test it right now, but

RewriteRule ^.*-id-(.*?)\.html$ index.php?id=$1 [L]

should get everything between the last "-id-" in the URL and ".html" and pass it to index.php (change it to fit your needs) as id via get.

(Notice the ? after .*, it makes the regular expression non-greedy, so that it matches as fewer characters as possible, making sure it's the last occurrence of "-id-")

MartinodF
tested and working, even with a-id-id-a-test-id-23.html ! ;)
MartinodF