URL masking with Laravel

How to mask URL in Laravel?
For example, when a user post this https://somewhere.com/anywhere.php and I want to mask it to become something like https://mywebsite.com/rxxx then https://mywebsite.com/rxxx redirects to https://somewhere.com/anywhere.php

Answer

I will walk you through with some few steps
1.first create a table in your database with a field that will hold the URL submitted by the user and also a field for a generated id. Note, you can use the id of the table but I would prefer you generate a random but unique id for each URL.
2. Example.

Assuming the URL submitted by the user is www.userweb.com and the generated unique id is rxxx, and your website name is www.mywebsite.com. the masked URL will now become www.mywebsite.com/rxxx.

  1. Next, anytime someone tries accessing the masked URL in our case www.mywebsite.com/rxxx, what happens behind the scene is that on your backend, you will get the id from the link which is rxxx and search against your table(the one you created in step one) and get the actual link then redirect the person to the actual website. In that way you can track the number of times the URL was clicked, etc.