Forum Moderators: phranque

Message Too Old, No Replies

Help needed for mod rewrite

for a pagination query

         

selomelo

1:18 pm on Jul 19, 2006 (gmt 0)

10+ Year Member



I desperately need help in mod rewrite for the following situation:

I have page that displays results fetched from a database like this:

show.php?action=show&word= [displays individual items]

show.php?action=search&by=[Letter]&nr_page=[Number] [pagination for letters A-z & numbers 0-9). Letter A have multiple pages, such as A1, A2, ... An.

The mod rewrite for the first is:
RewriteRule ^([A-Za-z0-9_-]*)\.html$ /subdirectory/show.php?action=show&word=$1
This displays pages as 1.html, 2.html, etc.

I tried to write another rewrite for the multiple pages, but I simply could not manage.
RewriteRule ^([A-Za-z0-9_-]*)\.html$ /subdirectory/show.php?action=search&by=$1&nr_page=$3

This should display pages in the form of A1.html, A2.html, etc. But it do not.

How can I rewrite for this?

Thank you in advance.

jdMorgan

2:04 pm on Jul 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem is that you've tried to use the back-reference "$3", but you have only defined one back-reference "$1" in the RewriteRule pattern. Back-references are defined by parenthesizing the parts of the pattern that you wish to reference in the substitution URL. You might want to review the section on back-references in the mod_rewrite Documentation.

There is also a thread [webmasterworld.com] in our library which may prove useful.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

smatts9

11:35 pm on Jul 19, 2006 (gmt 0)

10+ Year Member




I tried to write another rewrite for the multiple pages, but I simply could not manage.
RewriteRule ^([A-Za-z0-9_-]*)\.html$ /subdirectory/show.php?action=search&by=$1&nr_page=$3

This should display pages in the form of A1.html, A2.html, etc. But it do not.

How can I rewrite for this?


Try this:

RewriteRule ^([A-Za-z0-9-]+)([0-9]+)\.html$ /subdirectory/show.php?action=search&by=$1&nr_page=$2 [L]

jdMorgan

2:50 am on Jul 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Or use [NC] to make the compare of the alphabetic url-part case-insensitive:

RewriteRule ^([a-z]+)([0-9]+)\.html$ /subdirectory/show.php?action=search&by=$1&nr_page=$2 [NC,L]

You may omit the "+" signs as well, if the url is always one letter followed by one number.

Jim