Search code examples
isapi-rewrite

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


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?


Solution

  • 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]