API with Human-Readable URLs in PHP

Let's now make API addresses in the form of human-readable URLs. For example, we will pass the first and second number:

urlhttp://api.loc/1/100/

To implement human-readable URLs, first we will create an htaccess file, in which we will send all requests to index.php:

.htaccessRewriteRule .+ index.php

In the index.php file, we will get the requested URI:

api.loc/index.php<?php
  $uri = $_SERVER['REQUEST_URI'];
?>

After receiving the URI, you can parse the parameters and display a random number in the specified range:

api.loc/index.php<?php
  preg_match('#^/([0-9]+)/([0-9]+)/?$#', $uri, $match);
  
  if (isset($match[1]) and isset($match[2])) {
    echo mt_rand($match[1], $match[2]);
  } else {
    echo 'error';
  }
?>
Задание 1

Implement an API for working with years, according to the behavior described below.

Checks if a year is a leap year:

urlhttp://api.loc/leap/2025/

Returns the difference between years:

urlhttp://api.loc/diff/2025/2030/