【问题标题】:Redirect in based on cookie and prevent loop基于cookie重定向并防止循环
【发布时间】:2015-12-14 06:04:12
【问题描述】:

如果 cookie 未设置为 htaccess,我会尝试重定向,但我无法阻止重定向循环。

这是为了安装wordpress。

这是我现在的.htaccess

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]

我该怎么做?

【问题讨论】:

  • 尝试使用RewriteCond %{HTTP_COOKIE} !cookie_name [NC],不使用^并添加一个空格,因为您的cookie不一定是第一个。
  • 重定向循环持续存在。谢谢!

标签: php wordpress .htaccess redirect cookies


【解决方案1】:

这对我有用 - 如果设置了 cookie,请求不是文件或目录,请求将由 index.php 处理,否则将由 处理redirect.php,大​​概应该设置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]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-10
    • 2012-12-31
    相关资源
    最近更新 更多