1
I am developing an api. Basically it requests a page according to the request.
Example: http://localhost/mod/<name>/<version>
the problem is being /version. I made htaccess that 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
But if I require for example /mod/test/1.0 o no $_GET['version']
says 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 goes for /modpack/<slug>/<build>
RewriteRule /modpack/(.*)/(.*) /modpack.php?slug=$1&build=$2
yes ( just to complete the comment)
– FRNathan13
Must have to make a explode, the get doesn’t enter more (as far as I know) in this format...
explode('/', URL)
, then you have the segments and continue from there... I just don’t answer because I’m not 100% sure that this is the only/best way to do it– Miguel
I even thought of using the explode but the problem is if any user put a / in the version ai will bugger the system.
– FRNathan13
You can remove the
/
end-time,$url = rtrim('/', URL)
before making the explode– Miguel
I’ll try.
– FRNathan13