Not returning the second parameter

1

I'm developing an api. Basically it requests a page according to the request. Example: http://localhost/mod/<name>/<version> the problem is being / version. I did htaccess this way:

Options +FollowSymLinks
RewriteEngine on

RewriteRule /mod/(.*) /mod.php?name=$1
RewriteRule /mod/(.*)/(.*) /mod.php?name=$1&version=$2
RewriteRule /modpack/(.*) /modpack.php?slug=$1
RewriteRule /modpack/(.*)/(.*) /modpack.php?slug=$1&build=$2

However if I require eg /mod/test/1.0 or no $_GET['version'] it says that the index version is null.

<?php
    echo "It works! name=" . $_GET['name'] . ',version=' .$_GET['version'];
?>

I used this line: RewriteRule /mod/(.*)/(.*) /mod.php?name=$1&version=$2

But it puts the version together with the name:

  

Notice: Undefined index: version in C: \ xampp \ htdocs \ mod.php on line 2
  It works! name = test / 1.0, version =

The same thing happens in /modpack/<slug>/<build>

RewriteRule /modpack/(.*)/(.*) /modpack.php?slug=$1&build=$2
    
asked by anonymous 06.12.2016 / 16:39

1 answer

4

This is happening because. * is a very greedy regex, because it marries everything, including with the / bar, so you can not separate the parameters.

Correct is to improve this regex. Example: ([^\/]+) (not to mar a /)

RewriteRule /modpack/([^\/]+)/([^\/]+) /modpack.php?slug=$1&build=$2 
    
06.12.2016 / 20:20