# Smart redirect in .htaccess

**URL:** <https://www.phphelp.com/t/smart-redirect-in-htaccess/34538>\
**Category:** Code Snippets\
**Created:** [February 28, 2022, 11:20pm UTC](https://www.phphelp.com/t/smart-redirect-in-htaccess/34538 "2022-02-28T23:20:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RandalOulton](https://www.phphelp.com/user_avatar/www.phphelp.com/randaloulton/32/2492_2.png) [@RandalOulton](https://www.phphelp.com/u/RandalOulton)\
**Post date:** [February 28, 2022, 11:20pm UTC](https://www.phphelp.com/t/smart-redirect-in-htaccess/34538/1 "2022-02-28T23:20:19Z")

</div>

Wondering if this is something that can be done in an .htaccess file – to code a “smart redirect” based on current month.

* * *

THE BUSINESS NEED:

At the start of each month, I have to manually go into Yoast plugin and set a redirect for

> **[Food Calendar](https://www.cooksinfo.com/food-calendar/?fwp_FoodMonth=February)**
>
> What's happening when and where in the world of food: a calendar of special food days. Celebrate these food holidays with suggested activities and recipes, and learn about the history, literature and lore behind these delicious days!

to actually go to the page for the current month, so that people landing on that page see the food days for that particular month first.

Example:

At the very end of February, I manually set a redirect for that /food-calendar link

to be

…/food-calendar/?fwp\_FoodMonth=March

At the end of March, I will set it to go to …food-calendar/?fwp\_FoodMonth=April

etc.

THE CHALLENGE

I am often too busy or forget, so that sometimes this doesn’t happen until a week or two into the next month.

QUESTION  
Is this something that can be programmed in the .htaccess file? A bit of programming so that month number is detected from date, and that if month=1, then URL = …food-calendar/?fwp\_FoodMonth=January, if month=2, then URL = …/food-calendar/?fwp\_FoodMonth=February, etc?

---

<div class="post-metadata">

**Author:** ![phdr](https://www.phphelp.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@phdr](https://www.phphelp.com/u/phdr)\
**Post date:** [March 1, 2022, 1:31am UTC](https://www.phphelp.com/t/smart-redirect-in-htaccess/34538/2 "2022-03-01T01:31:32Z")

</div>

> [@RandalOulton](#):
>
> ?fwp\_FoodMonth=

The server-side code should setup and use the current month if the get parameter doesn’t contain a valid month, i.e. it’s not set, it’s empty, or it’s not a valid month name, otherwise use the supplied month value. Any link you provide on a page for the current month, would simply not have that get parameter in it. If you want to provide links to previous month(s), they would contain the corresponding month name in the get parameter.

---

<div class="post-metadata">

**Author:** ![deepvyas](https://www.phphelp.com/letter_avatar_proxy/v4/letter/d/e0b2c6/32.png) [@deepvyas](https://www.phphelp.com/u/deepvyas)\
**Post date:** [May 31, 2022, 1:00pm UTC](https://www.phphelp.com/t/smart-redirect-in-htaccess/34538/3 "2022-05-31T13:00:20Z")

</div>

> [@RandalOulton](#):
>
> Is this something that can be programmed in the .htaccess file? A bit of programming so that month number is detected from date, and that if month=1, then URL = …food-calendar/?fwp\_FoodMonth=January, if month=2, then URL = …/food-calendar/?fwp\_FoodMonth=February, etc?

Can help you with the solution.  
Let me know, If interested

Good Day  
Deep

---

<div class="post-metadata">

**Author:** ![RandalOulton](https://www.phphelp.com/user_avatar/www.phphelp.com/randaloulton/32/2492_2.png) [@RandalOulton](https://www.phphelp.com/u/RandalOulton)\
**Post date:** [May 31, 2022, 1:14pm UTC](https://www.phphelp.com/t/smart-redirect-in-htaccess/34538/4 "2022-05-31T13:14:46Z")

</div>

Update: I was able to meet the business need in another fashion. Cheers.
