尝试为Apache负载平衡器声明自定义cookie时出错


Getting error when trying to declare custom cookie for Apache load balancer

我学习了许多教程(例如http://www.markround.com/archives/33-Apache-mod_proxy-balancing-with-PHP-sticky-sessions.html/)并且已经建立了一个Apache负载均衡器,除了会话维持之外,它运行良好。

我正在尝试修改我的重定向(在我添加额外的标志(?)之前一直有效):

RewriteRule ^(.*)$ public_html/index.php - [CO=JSESSIONID:balancer.view-a:.ea-hq.com]

这会导致内部服务器错误:

C:/Web Server/Apache24/htdocs/.htaccess: RewriteRule: bad flag delimiters

因此,我的会话不会保留在两台服务器之间。

我在Windows服务器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文档以获取更多信息