NameSilo

Mod_rewrite confusing me

Spaceship Spaceship
Watch

ncwdavid

Established Member
Impact
3
Hey, I start learning how to use mod_rewrite yesterday and it's really confusing me. This is my file right now:

Code:
RewriteEngine on
RewriteRule ^category/([^/\.]+)/?$ categories.php?category=$1 [L]

That deals with these links:

category/card-tricks | categories.php?category=card-tricks
category/money-tricks | categories.php?category=money-tricks
category/street-magic | categories.php?category=street-magic
category/mentalism | categories.php?category=mentalism

The text in bold is gotten from a database. So for example I can go to the admin area and add a new category called "levitation-effects" and in the site navigation a new link will appear pointing to "category/levitation-effects".

When I go to "category/card-tricks" it will $_GET[] the category type which is "card-tricks" and do a query to the database to show all the card tricks. On that page the card tricks will have links like this:

category/card-tricks/card-trick-1 | tricks.php?name=card-trick-1
category/card-tricks/card-trick-2 | tricks.php?name=card-trick-2
category/card-tricks/card-trick-3 | tricks.php?name=card-trick-3
category/card-tricks/card-trick-4 | tricks.php?name=card-trick-4

I want everything to be controlled from the admin area like adding the categories and the tricks but how do I do that without having to change the ".htaccess" file everytime I add a new trick? The answer is probably simple as always. Please help me. Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
I must be missing something Don't you just need:

Code:
RewriteEngine on
RewriteRule ^category/([^/\.]+)/?$ categories.php?category=$1 [L]
RewriteRule ^category/[^/]+/([^/\.]+)/?$ tricks.php?name=$1 [L]
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
Appraise.net

We're social

Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back