credits: Paul Saad On The Way To The Vaal River, Johanneburg via photopin (license). posted on November 4th, 2016.

Creating URL Rewrites in Magento 2

Look ma! Without hands!

Here's a quick draft on how to create URL Rewrites in Magento 2:

/**
 * @var \Magento\UrlRewrite\Model\UrlRewriteFactory
 */
protected $urlRewriteFactory;

/**
 * @var int
 */
protected $storeId = 1;

/**
 * Redirects constructor.
 * @param \Magento\UrlRewrite\Model\UrlRewriteFactory $urlRewriteFactory
 */
public function __construct(
    \Magento\UrlRewrite\Model\UrlRewriteFactory $urlRewriteFactory
)
{
    $this->urlRewriteFactory = $urlRewriteFactory;
}

/**
 * @param string $oldUrl
 * @param string $newUrl
 */
public function createRewrite(string $oldUrl, string $newUrl)
{
    $urlRewrite = $this->urlRewriteFactory->create();
    $urlRewrite->addData(
        [
            'entity_type' => \Magento\UrlRewrite\Controller\Adminhtml\Url\Rewrite::ENTITY_TYPE_CUSTOM,
            'entity_id' => 0,
            'request_path' => $oldUrl,
            'target_path' => $newUrl,
            'redirect_type' => \Magento\UrlRewrite\Model\OptionProvider::PERMANENT,
            'store_id' => $this->storeId,
            'description' => null,
            'is_autogenerated' => 0,
            'metadata' => null
        ]
    );
    $urlRewrite->getResource()->save($urlRewrite);
}

Magento 2 Url Rewrites