我遵循了许多教程(例如 http://www.markround.com/archives/33-Apache-mod_proxy-balancing-with-PHP-sticky-sessions.html/ ),并设置了一个 Apache 负载均衡器,除了 session 维持之外,它运行良好。
我正在尝试修改我的重定向(直到我添加额外的标志(?):
RewriteRule ^(.*)$ public_html/index.php - [CO=JSESSIONID:balancer.view-a:.ea-hq.com]
这会导致内部服务器错误:
C:/Web Server/Apache24/htdocs/.htaccess: RewriteRule: bad flag delimiters
所以我的 session 不会保留在两台服务器之间。
我在 Windows Server 2013 上使用 Apache 2.4 和 PHP 5.5.11。
我该如何解决这个问题?
如果您需要我提供更多详细信息,请说出来。
我已经做出了改变:
RewriteRule ^(.*)$ - [CO=JSESSIONID:balancer.view-a:.ea-hq.com]
RewriteRule ^(.*)$ public_html/index.php
但现在许多文件无法加载,并且状态为 302“已找到”,并且在通过 Chrome 中的检查器查看时显示为空白。
RewriteRule ^(.*)$ public_html/index.php [CO=JSESSIONID:balancer.view-a:.ea-hq.com]
给了我相同的结果。
这是我的完整 .htaccess 文件,未进行 cookie 修改:
Options +FollowSymLinks
IndexIgnore */*
<FilesMatch "\.(ico|pdf|flv|jpe?g|png|gif|js|css|swf|eot|woff|ttf|svg)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FilesMatch>
RewriteEngine On
RewriteBase /
# Ignore rule if the real path exists, use that instead.
RewriteCond %{REQUEST_FILENAME} !-f
# Only use the filename and extension.
RewriteRule ^(?:[^/]+/)*([^.]+\.(?:gif|jpe?g|png|eot|woff|ttf|svg))$ public_html/images/$1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/importers
RewriteCond %{REQUEST_URI} !\.(gif|jpg|png)$
RewriteRule ^(.*)$ public_html/index.php
# Use below when apache is upgraded.
#FallbackResource public_html/index.php
#php_flag session.bug_compat_42 1
#php_flag session.bug_compat_warn 0
<IfModule mod_security.c>
SecRuleEngine Off
</IfModule>
最佳答案
RewriteRule 需要 2 或 3 个参数,您的命令有 4 个参数
正确的语法是
- 命令:重写规则
- 模式: ^(.*)$
- 替换: -
- 标志: [CO=JSESSIONID:balancer.view-a:.ea-hq.com]
该错误仅与语法问题相关,指定替换为 public_html/index.php 和 -(破折号)。
(来自文档)破折号(-)表示不应执行替换(现有路径不受影响地通过)。当需要应用标志而不更改路径时使用此方法。
所以我认为你只需要一个破折号而不是public_html/index.php(你可以分开写其他规则)。
示例
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/index.php/$1 [L,CO=JSESSIONID:balancer.view-a:.ea-hq.com]
看apache documentation了解更多信息
关于php - 尝试为 Apache 负载均衡器声明自定义 cookie 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23260743/