0

I want to redirect visitors to a certain page depending on if they have a cookie set or not. Would it be better to do this in PHP or htaccess? I'm a complete noob when it comes to htaccess but I feel like there would be an obvious speed advantage because it actually happens before the site is loaded, while the php happens after, am I right?

Henrik
  • 278
  • 3
  • 12
  • Yes you are right. See http://stackoverflow.com/questions/3978726/how-to-do-htaccess-redirect-based-on-cookie-value for information about redirecting based on a cookie. – Scopey Oct 24 '14 at 02:03

1 Answers1

0

Most of the time, the difference is probably negligible, but since the directives in the htaccess file is cached (would be even faster if you put rules in your server/vhost config), there isn't a need to hand the request off to a handler (like php).

Something like:

RewriteEngine On
RewriteCond %{HTTP_COOKIE} cookiename=cookievalue
RewriteRule ^(?!certain-page.php) /certain-page.php [L,R]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220