Manage Redirects Based on the Referer in Your Laravel Project

Redirect to different pages in multiple time periods

Nowadays a lot of companies are increasing their marketing efforts to get the best results as possible. Of course, the way they do that varies, but we often see that multiple channels and multiple domain names are involved. But how do you handle changes? And new landing pages? For every campaign?

Current habbits

One things you can do is every time a campaign or ad (for a specific region?) is changing, you go along all the (ad)platforms and change the new direction urls. May take some time.. Don’t it?

New approach

The Laraval package laravel-referer-redirector gives you the opportunity to easily manage those redirects, based on the referer plus for different time periods.

This means that you can set a referer and let this referer redirect to /specific-page-1 in week 1 and redirect it to /specific-page-2 in week 2 etc.

Another example:
Catch visits from referer: facebook.com/p/etc
Redirect to: my-site.com/temporary-offer
Start: today
End: next monday

This is also handy for companies that are using landing page domains. Those referers are redirecting to the companies website, but you may want to handle those visits differently per campaign.

How does the package work?

As shown on github, you can simply add a new redirect via CLI:

php artisan referer:make {referer_url} {redirect_url}

If you don’t add a start + end date the redirect will start now without an end. Optionally you can add those dates (Carbon logic) by adding those options to the end:

--start={start_date} --end={end_date}

Using the example:

php artisan referer:make facebook.com/p/etc my-site.com/temporary-offer --start="today" --end="next monday"

To list all the created referer-redirects:

php artisan referer:list

To remove a single redirect you can use the remove function combined with the referer-redirect ID:

php artisan referer:remove id

To remove all redirects of a referer use the referer_url as input:

php artisan referer:remove referer_url

More details on installation and usage, check the GitHub repo.


Hopefully this will help you and your project to easily handle redirects based on the referer. Give it a shot and let us know what you think!

I’m also curious for which purposes you’re going to use it. Let me know in the comments below.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.