[vox-tech] Question related to Apache mod_rewrite and regular expressions

David Spencer spencer at pageweavers.com
Mon Apr 20 15:36:35 PDT 2009


I've killed the better part of the morning and this afternon trying to  
figure out this use of Apache's mod_rewrite. What I'm trying to do is  
this:

For the sake of backward compatibility, I'd like to take series of  
discrete pages that were created with HTML and generalize them with a  
database lookup page in PHP. Some example URLs would be like this:

product-This-Product.php
product-Another-Product.php
product-Yet-More-Product.php
product-Lotta-Product.php

and convert them within Apache internally to pages like this:

product.php?name=This-Product
product.php?name=Another-Product
product.php?name=Yet-More-Product
product.php?name=Lotta-Product

I'm the first to admit that I'm not a whiz with either RegEx or  
Apache. However, after a lot of reading, I came up with this:

RewriteEngine On
RewriteRule ^/?product-([A-Za-z0-9-]+)\.php$ product.php?name=$1  
[ R=301,L]

But Apache is choking on it so I can't even figure out how close I am  
to getting it working.

To further make things difficult, I need to skip over other pages that  
aren't product related. Is there somebody out there who can crack this  
nut?

Thanks so much!

-- Dave Spencer, PageWeavers


More information about the vox-tech mailing list