[thelist] Mod rewrite question

Ari Constancio ari.constancio at gmail.com
Fri Jun 13 08:39:54 CDT 2008


On Fri, Jun 13, 2008 at 2:24 PM, Chrome <admin at chrome.me.uk> wrote:
>> What I've got now is
>>
>> RewriteRule ^category/([a-zA-Z0-9_]+)/$ browse.php?cat=$1 [QSA,L]
>>
>> Which allows me to link to my category pages like so:
>>
>> www.domain.com/category/CATEGORYNAME/
>>
>> But now I'd like to add in the page numbers, like:
>>
>> www.domain.com/category/CATEGORYNAME/1/
>> www.domain.com/category/CATEGORYNAME/2/
>> Etc...
>>
>> This sort of works...
>> RewriteRule ^category/([a-zA-Z0-9_]+)/(page[0-9*]/)$
>> browse.php?cat=$1&pageNum_productinfo=$2 [QSA,L]
>
> I don't know much about mod_rewrite but I believe the multiple digit problem
> is caused by [0-9*] which should be [0-9]*
>
> Might bring you a step closer
>
>> But, if there's no page number, then I get a 404. And, if the page
>> number is more than single digit, I get a 404.
>>
>> Also, is it possible to make it work if the last / is missing in the
>> URI?
>
> Try this (page[0-9]*/?)?$

Hi,

> I don't know if the ? works the same as with Perl compatible regexes in
> mod_rewrite

It seems so (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html).
The second pattern gets optional with '?' , but is 'page' supposed to
be there when there's no number?

Probably something like this:
RewriteRule ^category/([a-zA-Z0-9_]+)/(page[0-9]+/?)?$
browse.php?cat=$1&pageNum_productinfo=$2 [QSA,L]

www.domain.com/category/CATEGORYNAME/page1/ ->
www.domain.com/browse.php?cat=CATEGORYNAME&pageNum_productinfo=page1

Cheers,
Ari Constancio



More information about the thelist mailing list