I'm using WordPress on an Apache server & would like to use my .htaccess to set a cookie when someone first lands on my site.
If possible I'd set TWO Cookies to:
- store the full URL
- store the value in a parameter in the URL (e.g. teamname)
Ordinarily in PHP, I'd just have:
function set_user_cookie() {
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
if (!isset($_COOKIE['LandingPageURL'])) {
setcookie('LandingPageURL', $url, time()+2678400, "/");
}
}
add_action( 'init', 'set_user_cookie');
However we've been noticing issues with caching so I wonder if it's possible to achieve this within my .htaccess instead.
Example URL: www.example.com/?teamname=Chicago+Bulls