ISAPI Rewrite Rule For Multiple Query String Parameters

586 Views Asked by At

I'm trying to rewrite a URL with 2 query string parameters using HeliconTech ISAPI_Rewrite Version 3. I'm able to rewrite the URL with 1 parameter but I can't figure out the rule(s) for rewriting 2.

Original URL:

http://example.com/index.php?id=1234&name=John-Edward-Smith

Desired rewritten URL

http://example.com/id/1234/name/John-Edward-Smith

My current .htaccess:

RewriteEngine On
RewriteRule   ^id/(.+)$  index.php?id=$1   [L, NC]

My current .htaccess file successfully rewrites the first parameter (id). My question is how do I modify the rule or add an extra rule to also rewrite the 2nd parameter (name)?

2

There are 2 best solutions below

0
On BEST ANSWER

Should be like this:

RewriteRule ^id/(\d+)/name/([^./]+)$ index.php?id=$1&name=$2 [NC,L]
RewriteRule ^id/(\d+)$ index.php?id=$1 [NC,L]
0
On

Perhaps you could try this:

# Rewrite with the name
RewriteRule ^id/(\d+)/name/([a-z0-9-]+)$ index.php?id=$1&name=$2 [L,NC]

# Rewrite with only the ID
RewriteRule ^id/(\d+)$ index.php?id=$1 [L,NC]