Skip to content
Advertisement

How to create redirect links with my own url?

I am creating a website with Laravel. I will promote some products via affiliation. I have some affiliates links like http://wwww.example.com/aff.php?id=123

I would like to have links like http://www.example.com/go/nameofproduct that redirect to affiliate links

Affiliates links are in a table in my database.

How can I do ?

Thanks

Advertisement

Answer

// define the route as you need 'go/{name of the product variable}' 
Route::get('go/{nameOfProduct}','path/ToYourController@goTo');

// method in your controller
function goTo($nameOfProduct) {
 
  // Add some validations for $nameOfProduct and fetch mapped redirect link from your database

  $redirectLink = ' http://wwww.example.com/aff.php?id=123' // fetch from database 

  return redirect()->away($redirectLink);
}

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement