| |
| |
|
|
|
|
| |
|
| |
|
| :: |
| Author |
Message |
kred
Joined: 14 Aug 2007 Posts: 3
|
Posted: Tue Aug 14, 2007 8:23 am Post subject: adding a second variable? simple right? |
|
|
Hi all,
I have a product page on a site I'm working on, and I am using this rewrite rule
| Code: | | RewriteRule ^\category/([A-Z][a-z](.*)+)$ /category.php?cat=$1 [L] |
this gets the name of the category for the php script. THis works great and I'm not having any problems.
The problem is, that when there are more than 12 products on the page I want to break up the pages into 1,2,3 or how ever many other pages are. The way I am doing that is by adding "category?page=#" to the URL or like this "/catergory/page#".
Now my problem is that I don't know how to add that new variable page# to my rewrite rule. I tired something like this:
| Code: | | RewriteRule ^\category/([A-Z][a-z](.*)+)/([0-9]+)$ /category.php?cat=$1&page=$2 [L] |
but that didnt work.
What I need to do is pass both variables into the category.php page, but only when there are both var to be passed, - because not all the products have more than 1 page -
I hope that I have written my issue out clearly and would appreciate any help.
Thanks
K |
|
|
| Back to top |
|
 |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 3477
|
Posted: Tue Aug 14, 2007 9:01 am Post subject: Re: adding a second variable? simple right? |
|
|
And welcome
First, I don't think you really need the backslash, and you can simplify a bit your RegEx :
| Code: | | RewriteRule ^category/([a-z0-9_-]+)$ /category.php?cat=$1 [L,NC] |
The [a-z0-9_-] means all a to z chars, plus numbers and "_" and "-", which is most likely what you are using in your titles. The NC flag stands for No Case, will thus match A-Z and a-z.
If you are using other chars, you may want to open it more :
| Code: | | RewriteRule ^category/(.+)$ /category.php?cat=$1 [L,NC] |
The dot means "any string", but it's generally faster to specify the chars to match.
Then, to add pagination, you must first decide your URL standard.
If you want to go for URLs like : /category/cat-title/pagexx, you shall use :
| Code: | | RewriteRule ^category/([a-z0-9_-]+)(/page([0-9]+))?$ /category.php?cat=$1&page=$3 [L,NC] |
This rewriterule will deal with both paginated and regular links, thanks ot the question mark "?". Note that this implies the page=$3, $2 being used to match the whole pagination string (/pagexx) where we only want the xx (thus the next var captured). |
_________________ phpBB SEO || SEO Forum || Forum Référencement
GYM Sitemap & RSS for phpBB3 has been released ! || GYM Sitemap & RSS for phpBB3 est disponible ! |
|
| Back to top |
|
 |
kred
Joined: 14 Aug 2007 Posts: 3
|
Posted: Tue Aug 14, 2007 10:21 am Post subject: Re: adding a second variable? simple right? |
|
|
Thanks for the quick reply.
I tried using your line but ran into some other complications.
1. I am using "." - the dot key in my URL's - ie. www.mysite.com/category/Judo.Brazilian_Jiu-Jitsu/2 - so I changed your line to:
| Code: | | RewriteRule ^\category/(.+)(/([0-9]+))?$ /category.php?cat=$1&page=$3 [L,NC] |
but that is giving me the whole string, ie. "Judo.Brazilian_Jiu-Jitsu/2" instead of just "Judo.Brazilian_Jiu-Jitsu" as $1 - - and that throws my SQL query out of whack.
Is there a way to stop $1 before the "/", or should I strip it in PHP?
Thanks again
K |
|
|
| Back to top |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 3477
|
|
| Back to top |
|
 |
kred
Joined: 14 Aug 2007 Posts: 3
|
Posted: Tue Aug 14, 2007 10:46 am Post subject: Re: adding a second variable? simple right? |
|
|
Thanks again,
I tried adding a "." there but didn't use the "\" so I got an error - I'm still new to this sport.
You have fixed my problem, I owe you a beer or whatever you would prefer to drink.
Thanks
K |
|
|
| Back to top |
|
 |
SeO Administrateur - Site Admin

Joined: 15 Mar 2006 Posts: 3477
|
|
| Back to top |
|
 |
|
|
| Navigation |
Similar Topics |
|
|
|
|
|
|
|
| |
|
|
|
|
| |
|
|
|
|
| |