.htaccess friendly urls

software development


I have a dynamic website, and I’m trying to change this:


Into something friendlier like this:

http://www.bundoranpress.com/14/13/ (I’ll switch the numbers later)

Anyhow, this is what I’m using but I’m having no luck (I’ve even used htaccess generators):

RewriteEngine On
RewriteRule /(.)/(.)/$ 03product.php?category_id=$1&product_id=$2

But I’m getting nothing…no changes whatsoever. I’ve tested my htaccess page using a very simple test (and my htaccess is active) but in this regard…can’t seem to get anywhere.


Ok, first the RewriteRule is saying match all lines with slash /, any character zero or more times (.), slash /, any character zero or more times (.)

Your supplied Url doesn’t have that in it so you won’t match. Everything kind of works backwards in mod_rewrite

Warning untested code below :slight_smile:
What you want is something like:

RewriteCond %{REQUEST_URI} ^/03product.php
RewriteCond %{QUERY_STRING} category_id=([0-9]+)
RewriteCond %{QUERY_STRING} product_id=([0-9]+)
RewriteRule .* 03product.php/$1/$2



RewriteEngine On
RewriteBase /
RewriteRule ^([0-9]+)/([0-9]+)$ 03product.php?category_id=$1&product_id=$2 [L]

I’ve linked to the reference documentation for you.



Try changing the regexp to


to catch /14/13/



will catch either /14/13 or /14/13/


Awesome. That works great. I’m not familiar with reg expressions (if that’s what they’re called). I’ve changed it a little bit so it will now do that with the names, rather than just numbers. However…

Is there a way to substitute spaces in strings? So instead of this: product/02/a%20book%20I%20love I’d like product/02/a-book-I-love (for instance)


You would need a RewriteRule with the “next” flag to substitute characters.