Forum Moderators: phranque
So far I have a htaccess in certain subdirectorys of a website I'm re-designing, and I am trying to write my own regexp for a section.
The product codes the client uses are in a particular format. They consist of 4 letters followed by 5 numeric digits. The first two letters of each product code are ALWAYS AA. the following two letters can only be one of three possibilities. BB, DE or RS.
the following are examples of his product code format
AABB00001 = product number 00001 in category AABB
AADE92501 - product number 92501 in category AADE
AARS12341 - product number 12341 in category AARS
what we are trying to create is a re-write rule for the site's redirects and so far I am trying to no avail in getting a regexp close.
We are trying to achieve the following...
http://www.domain.com/products/AABB00001.html
gets pointed to
http://www.domain.com/view_products.php?product_id=AABB00001
I'm starting with
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^([^.]+)\.html$ ../view_products.php?product_id=$1 [L] what we now want to do is expand our rule to ensure that the product code entered is in the correct format. Anything that isnt in the correct format will result in a 404 page.
I know that [aA][aA] will match the first 2 A's (case insensitive) and that \b[0-9][0-9]{4}\b will match the trailing 5 digits.
Any suggestions on how I can create the full expression?
Many thanks!
RewriteRule ^(AA(BB¦DE¦RS)[0-9]{5})\.html$ ../view_products.php?product_id=$1 [NC,L]
Replace the broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim
[edited by: jdMorgan at 1:08 am (utc) on Nov. 22, 2007]
thanks for the advice. Am I right in thinking that exp would match anything where the first 4 characters are any character from a-zA-Z?
He wants it so it matches anything starting with aa (case insensitive), followed by either bb, de or rs (again all case insensitive), folowed by the 5 digit code.
Many thanks so far!