Simple rewrite rule for passing CGI parameters

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 3
Joined: 03 Apr 2012, 15:49

Simple rewrite rule for passing CGI parameters

03 Apr 2012, 16:00

Hi,

I have been trying, without luck, to form a rewrite to capture incoming requests that have page numbers, like this:

http://www.xyz.com/strawberry-milkshakes.cfm?page=1

I have this:

RewriteRule ([^\?]*)/strawberry-milkshakes.cfm$ $1/catpage.cfm?Category_ID=100 [L]

so that the page "strawberry-milkshakes.cfm" is served by my generic catpage.cfm template, which passes Category_ID 100 in this case (other flavours have other Category_ID values).

However, I cannot get pagination to work. I need to pass the page parameter as well, if it exists. Someone may request:

http://www.xyz.com/strawberry-milkshakes.cfm?page=1

so I need Category_ID = 100 and page = 1 passed back.

Can anyone please show me the syntax? Do I need one rule or two?

Help appreciated.

Thanks,
Mark

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Simple rewrite rule for passing CGI parameters

04 Apr 2012, 10:06

Hello,

What request do you want to make from a browser? Where should it point to?
this will help to create a simple rule(s)

regards
Andrew

User avatar
Posts: 3
Joined: 03 Apr 2012, 15:49

Re: Simple rewrite rule for passing CGI parameters

04 Apr 2012, 11:01

>What request do you want to make from a browser? Where should it point to?

Say that I enter:

http://www.xyz.com/strawberry-milkshakes.cfm?page=3

the page should load:

http://www.xyz.com/strawberry-milkshake ... 100&page=3

but only show http://www.xyz.com/strawberry-milkshakes.cfm?page=3 in the browser.

I have this rule at present:

RewriteRule ([^\?]*)/strawberry-milkshakes.cfm$ $1/catpage.cfm?Category_ID=100 [L]



Thanks,
Mark

User avatar
Posts: 1264
Joined: 07 Mar 2012, 10:16

Re: Simple rewrite rule for passing CGI parameters

05 Apr 2012, 06:14

Hello,

In this case it's only one rule. I see that you need your Category_ID=100 static, so the rule should look like:

Code: Select all
RewriteCond %{QUERY_StRING} ^page=([^&]+)$
RewriteRule ^strawberry-milkshakes\.cfm$ /strawberry-milkshakes.cfm?Category_ID=100 [NC,QSA,L]


Regards
Andrew

User avatar
Posts: 3
Joined: 03 Apr 2012, 15:49

Re: Simple rewrite rule for passing CGI parameters

05 Apr 2012, 14:31

Thanks Andrew.

In fact, I only needed to add QSA and it works.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 15 guests