Need a little Regex help

DaiShan

Diamond Member
Jul 5, 2001
9,617
1
0
Ok, I'm trying to use mod_rewrite to rewrite URL's of the form
/promotional-products/product.php to /promotional-products/products.php?cat=product

E.G.

/promotional-products/t-shirts.php no longer exists as a php file. Instead products.php will now create the page from the database, but for search engine reasons we still want the user / search engine to be able to click on the link and be taken to the following address: /promotional-products/products.php?cat=t-shirts Here is the regex I have:

RewriteEngine On
RewriteRule ^/promotional-products/*$1 /promotional-products/products.php?cat=$1 [PT]

I've tried many permutations of this from many separate tutorials, but nothing seems to work (mod_rewrite is installed and enabled) Can someone please point me in the right direction?
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Try to see if this works (note that i didn't test them so it might not work):

RewriteRule ^promotional-products/(.+)\.php$ promotional-products/products.php?cat=$1 [L]

To enable callback (or whatever it's called), you need to enclose the expressions in (parantheses), and then refer to them as $1, $2, etc.
 

DaiShan

Diamond Member
Jul 5, 2001
9,617
1
0
/edit You had it right, we both forgot the leading slash however. For those who are interested this is the full code:

RewriteEngine On
RewriteRule ^/promotional-products/(.+)\.php$ /promotional-products/products.php?cat=$1 [L]

Thanks!
 

stndn

Golden Member
Mar 10, 2001
1,886
0
0
Glad to know it worked -)

IIRC, you can also put this before your RewriteRule so you don't have to put a leading slash:

RewriteEngine On
RewriteBase /

RewriteRule ..... blah blah blah


-stndn.