Not strictly php, but uses regexes which I suck at...
I'm using database values to fake a directory structure, eg:
site.com/products/category/productname
which I want (for now, anyway) to end up at:
site.com/products/index.php?cat=category&prod=productname
I've tried this code and get a 404:
RewriteEngine On
RewriteRule ^products/([a-z]+)/([a-z]+)/$ products/index.php?cat=$1&prod=$2 [L]
I've placed the .htaccess file in my root folder so it should be working.
Any ideas?
Matt
.htaccess rewrite rule
Moderator: General Moderators
-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: .htaccess rewrite rule
I can never remember when the regex should start with a / or not. There's that to test, and how your expression requires a trailing / but there wasn't one in your URL.
(You'll probably want the QSA flag later on.)
Code: Select all
RewriteRule ^/?products/([a-z]+)/([a-z]+)/? products/index.php?cat=$1&prod=$2 [QSA]-
mattpointblank
- Forum Contributor
- Posts: 304
- Joined: Tue Dec 23, 2008 6:29 am
Re: .htaccess rewrite rule
Removed the slash and ? at the start and it worked - thanks a ton.