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?
Asked
Active
Viewed 79 times
1 Answers
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