Unwanted backslash on parameter while using RewriteRule

  .htaccess, php

URL Examples:

1) mydomain.com/coding/mysql/
2) mydomain.com/coding/mysql/?contactId=333&UTM=aff
3) mydomain.com/coding/?contactId=333

This is my htaccess file

RewriteEngine On
RewriteRule ^(.+)/(.+)/?$ index.php?book=$1&chapter=$2 [NC,L,QSA]
RewriteRule ^(.+)/?$ index.php?book=$1 [NC,L,QSA]

So I print_r($_REQUEST) on the index.php file to see what I was getting:

1) Array ( [book] => coding [chapter] => mysql/ )
2) Array ( [book] => coding [chapter] => mysql/ [contactId] => 333 [UTM] => aff )
3) Array ( [book] => coding/ [contactId] => 333 [UTM] => aff )

My problem is that I don’t want the / showing in the last available parameter
It would not add the / if I call the examples above like this:

1) mydomain.com/coding/mysql
2) mydomain.com/coding/mysql?contactId=333&UTM=aff
3) mydomain.com/coding?contactId=333

What do I need to change on my rules to have mydomain.com/coding/mysql?contactId=333&UTM=aff resulting in Array ( [book] => coding [chapter] => mysql [contactId] => 333 [UTM] => aff )

Thanks! Much appreciated. I hope that makes sense.

Source: Ask PHP

LEAVE A COMMENT