ISAPI Rewrite : Append querystring to the rewrited URl's Query String

457 views Asked by At

Actually, using the following ISAPI rule

RewriteCond %{HTTP:Host} ^domain.com$
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L]

I'm rewriting the following URL

htttp://www.domain.com/Product-name/

to

htttp://www.domain.com/test.cfm?ProducID=xxxx

This is working fine, But when I use the querystring in URL, it is not working

For Egs: The following URL is not working

htttp://www.domain.com/Product-name?categoryID=YYYY

I need to rewrite the above URL as follows

htttp://www.domain.com/test.cfm?ProducID=xxxx&categoryID=YYYY

I've used the following rule, but no luck

RewriteCond %{QUERY_STRING} ^param=(\d+)$ [NC] 
RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx?param2=%1? [NC,L]

So is there any solution for this?

2

There are 2 answers

0
Rajesh Manilal On BEST ANSWER

The following rule, appends the query string to the rewritten URL's Querystring and avoids the 404 error

URL With Querystring and Trailing slash(/)

RewriteRule ^/Product-name/\? /test.cfm?ProductID=xxxx [NC,L,QSA]

URL With Querystring and Without Trailing slash(/)

RewriteRule ^/Product-name\? /test.cfm?ProductID=xxxx [NC,L,QSA]

URL Without Querystring and with Trailing slash(/)

RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L]

URL Without Querystring and Trailing slash(/)

RewriteRule ^/Product-name$ /test.cfm?ProductID=xxxx [NC,L]
1
TonyCool On

If you are using ISAPI_Rewrite 3, then you should add QSA flag to append original query string to the resulting URL:

RewriteRule ^/Product-name/$ /test.cfm?ProductID=xxxx [NC,L,QSA]