Redirect based on last numbers in url after the hyphen

By : Ian
Source: Stackoverflow.com
Question!

I am trying to do the following redirect using .htaccess:

http://www.example.com/blue/widgets/item-4_description-12345.htm to /index.php?id=12345

What would be the best regular expression to extract the digits after the last hyphen and a dot?

By : Ian


Answers

Perhaps the following:

RewriteRule ^.*-(\d )\.htm$ /index.php?id=$1

Untested, but see if that helps. This is based on my knowledge of RegEx, and the examples I found from various places.

There's also a helpful site that automates the process of .htaccess modifications, though I don't see anything pertaining to RegEx.



This video can help you solving your question :)
By: admin