Reputation: 2143
I'm sure there is something out there to answer my question, but I cannot find it.
In short: I want to use .htaccess and mod_rewrite to clean up my urls.
Currently I have 3 possible variables.
c for category, m for manufacturer, and p for page.
if there is just c, it will display all the possible manufacturers under that category. If there is a c and an m it will display the first 30 items of that manufacturer under that category, and then if there is more then 30 you can go to the next page, p, and on.
This is what I'm trying to accomplish:
index.php?c=Category1 turns into /Category1 index.php?c=Category1&m=Manufacturer1 turns into /Category1/Manufacturer1 index.php?c=Category1&m=Manufacturer1&p=1 turns into /Category1/Manufacturer1/page/1 (or Category1/Manufacturer1/1/)
I have tried a couple things I've found but I can't translate them to my scenario.
I've tried
RewriteEngine On
RewriteRule ^(.*) index.php?p=$1
and
RewriteEngine On
RewriteRule ^([^/]+)/?$ index.php?p=$1
however
RewriteEngine On
RewriteRule ^page/([^/]+)/?$ index.php?p=$1
works but that is not what I want for the first 2 parameters.
What rules do I need?
Upvotes: 0
Views: 114
Reputation: 143886
You can either make 3 separate rules or if you don't care about blank $_GET
variables, use optional groupings:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?c=$1&m=$2&p=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?c=$1&m=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /index.php?c=$1 [L]
or
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)(?:/([^/]+)|)(?:/([^/]+)|)/?$ /index.php?c=$1&m=$2&p=$3 [L]
Upvotes: 2