paging with mod_rewrite

Discuss practical ways rearrange URLs using mod_rewrite.

paging with mod_rewrite

Postby jonnyd91 » Wed Nov 19, 2008 6:12 pm

Hi I am using a rewrite rule to make my urls more friendly.

RewriteRule ^(.*)products/(.*)/(.*)$ $1/products?BRAND=$2&VENDORCODE=$3 [PT,L]

which changes this:
http://www.mysite.com/products?BRAND=10 ... ORCODE=471
to this:
http://www.mysite.com/products/10-Deep/471

However I am also using a 3rd party paging tag and to make it more complicated i am running apache in front of tomcat. So my application is primarily in jsp.

When i go to the page links the pager creates the urls turn this:

http://www.mysite.com/products?BRAND=10 ... ORCODE=471

to this:
http://www.mysite.com/category.jsp?pager.offset=20

What would I have to do to get the mod rewrite to work with my pager?
the paging works fine with the old links
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby jonnyd91 » Wed Nov 19, 2008 7:08 pm

i guess what i need to try and do is change this:
http://www.test.com/products/10-Deep/47 ... .offset=16

To this some how.
http://www.test.com/category.jsp?pager.offset=20
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby richardk » Thu Nov 20, 2008 1:22 pm

So if the request has /products/...?pager.offset=n you want it to go to /category.jsp?pager.offset=n? Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?pager.offset=[0-9]+(&.*)?$ [NC]
RewriteRule ^products/.+$  /category.jsp [QSA,PT,L]

RewriteRule ^products/(.+)/([0-9]+)$ $1/products?BRAND=$1&VENDORCODE=$2 [PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jonnyd91 » Thu Nov 20, 2008 8:36 pm

Ok,
I get a 404 error.

Let me give a bit more info.

i am using jkmount to pass on the servlet requests to tomcat.

cp_jkmount.conf
JkMount /products/* ajp13
Above is the servlet i am giving the access to

When i first go to the page the url looks like this:
http://www.mysite.com/products?BRAND=Al ... ORCODE=471

When i click on next page it looks like this:
http://www.mysite.com/category.jsp?pager.offset=20

Now products is the servlet and category.jsp is the jsp page the the request gets passed back to.

My ultimate goal is to get rid of the "?" and"=" and replace it with "/"

the only "?" i cant get rid of is here:
category.jsp?pager.offset=20 this comes from the pager tag, so i just wont replace it with an"/"

This rule worked to get my slashes in place:
RewriteRule ^(.*)products/(.*)/(.*)$ $1/products?BRAND=$2&VENDORCODE=$3 [PT,L]

But when i click on the other page numbers they dont work and keep displaying the same page.

Any help would be appreciated

thanks
John
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby richardk » Fri Nov 21, 2008 1:00 pm

But when i click on the other page numbers they dont work and keep displaying the same page.

What links don't work?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?pager.offset=[0-9]+(&.*)?$ [NC]
RewriteRule ^(?:.*/)?products/.+$  /category.jsp [QSA,PT,L]

RewriteRule ^(?:.*/)?products/(.+)/([0-9]+)$ $1/products?BRAND=$1&VENDORCODE=$2 [PT,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jonnyd91 » Fri Nov 21, 2008 1:59 pm

this link didnt work:
http://www.mysite.com/products/10-Deep/471

i will give that a try when i get home

thanks
john
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby jonnyd91 » Fri Nov 21, 2008 5:04 pm

ok, now i get a 500 internal server error
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm

Postby richardk » Sun Nov 23, 2008 9:22 am

Try removing both
Code: Select all
^(?:.*/)?


I am not sure if it is what you want anyway.
What is the link you would like in the page source?
What is the current link in the page source?
Where should the new link go to? The current link?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby jonnyd91 » Sun Nov 23, 2008 9:20 pm

i am scrapping this. I am going to recode the paging. thanks for all your help
jonnyd91
 
Posts: 13
Joined: Sun Nov 16, 2008 9:46 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 15 guests

cron