I am trying to redirect if cookie is not set with htaccess
, but I can't prevent the redirection loop.
It's for wordpress installation.
Here is my .htaccess
at the moment:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_COOKIE} !^cookie_name[NC]
RewriteCond %{REQUEST_URI} !^/page_to_redirect/ [NC]
RewriteRule .* /page_to_redirect/ [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
How can I do that?
This works for me - if the cookie is set, the request isn't a file or directory, the request will be handled by index.php , otherwise it will be handled by redirect.php , which should presumably set the cookie.
RewriteEngine On
RewriteCond %{HTTP_COOKIE} cookie_name [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule .* /redirect.php [L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.