Apache Mod_rewrite 规则在一台服务器上有效,但在另一台服务器上无效

Apache Mod_rewrite 规则在一台服务器上有效,但在另一台服务器上无效

我在 httpd 2.2.15 上使用 mod_jk 和 mod_rewrite。我有一条规则....

RewriteCond %{REQUEST_URI} !^/video/play\.xhtml.*
RewriteRule ^/video/(.*) /video/play.xhtml?vid=$1 [PT]

我只想将 /video/videoidhere 之类的内容重写为 /video/play.xhtml?vid=videoidhere。这在我的开发机器上运行良好,但在生产过程中我得到了 404(由 Jboss 生成,而不是 Apache)。

这是 prod 上的 access.log 和 rewrite.log 的尾部(已损坏)。rewrite.log 在 dev 上完全相同(正常工作)

applying pattern '^/video/(.*)' to uri '/video/46279d4daf5440b2844ec831413dcc3b'
RewriteCond: input='/video/46279d4daf5440b2844ec831413dcc3b' pattern='!^/video/play\.xhtml.*' => matched
rewrite '/video/46279d4daf5440b2844ec831413dcc3b' -> '/video/play.xhtml?vid=46279d4daf5440b2844ec831413dcc3b'
split uri=/video/play.xhtml?vid=46279d4daf5440b2844ec831413dcc3b -> uri=/video/play.xhtml, args=vid=46279d4daf5440b2844ec831413dcc3b
forcing '/video/play.xhtml' to get passed through to next API URI-to-filename handler
"GET /video/46279d4daf5440b2844ec831413dcc3b HTTP/1.1" 404 420 "-" "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.6) Gecko/20100628 Ubuntu/10.04 (lucid) Firefox/3.6.6"

我可以访问 http://www.fivi.com/video/play.xhtml?vid=46279d4daf5440b2844ec831413dcc3b 但不是/video/46279d4daf5440b2844ec831413dcc3b

两个服务器甚至使用完全相同的 httpd.conf 和模块。

我用...构建了 Apache

./configure --prefix /usr/local/apache2.2.15 --enable-alias --enable-rewrite --enable-cache --enable-disk_cache --enable-mem_cache --enable-ssl --enable-deflate

谢谢,梅森

----更新---- -mod-jk.conf

JkWorkersFile /usr/local/apache2.2.15/conf/workers.properties
JkLogFile /var/log/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompatUnparsed -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkShmFile run/jk.shm
<Location /jkstatus>
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

-workers.properties

worker.node1.port=8009
worker.node1.host=75.102.10.74
worker.node1.type=ajp13
worker.node1.lbfactor=20
worker.node1.ping_mode=A #As of mod_jk 1.2.27
worker.node2.port=8009
worker.node2.host=75.102.10.75
worker.node2.type=ajp13
worker.node2.lbfactor=10
worker.node2.ping_mode=A #As of mod_jk 1.2.27
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node2,node1
worker.loadbalancer.sticky_session=True
worker.status.type=status

-httpd.conf

ServerName www.fivi.com:80
Include /usr/local/apache2.2.15/conf/mod-jk.conf
NameVirtualHost *
<VirtualHost *>
  ServerName *
  DocumentRoot /usr/local/apache2/htdocs
  JkUnMount /* loadbalancer
  RedirectMatch 301 /(.*) http://www.fivi.com/$1
</VirtualHost>

<VirtualHost *>
  ServerName www.fivi.com
  ServerAlias www.fivi.com images.fivi.com 
  JkMount /* loadbalancer
  JkMount / loadbalancer

[root@fivi conf]# /usr/local/apache2.2.15/bin/httpd -M

Loaded Modules:
 core_module (static)
 authn_file_module (static)
 authn_default_module (static)
 authz_host_module (static)
 authz_groupfile_module (static)
 authz_user_module (static)
 authz_default_module (static)
 auth_basic_module (static)
 cache_module (static)
 disk_cache_module (static)
 mem_cache_module (static)
 include_module (static)
 filter_module (static)
 deflate_module (static)
 log_config_module (static)
 env_module (static)
 headers_module (static)
 setenvif_module (static)
 version_module (static)
 ssl_module (static)
 mpm_prefork_module (static)
 http_module (static)
 mime_module (static)
 status_module (static)
 autoindex_module (static)
 asis_module (static)
 cgi_module (static)
 negotiation_module (static)
 dir_module (static)
 actions_module (static)
 userdir_module (static)
 alias_module (static)
 rewrite_module (static)
 so_module (static)
 jk_module (shared)
Syntax OK

答案1

这可能是一个愚蠢的问题,但我偶尔(Debian / Ubuntu)会遇到 ReWrite 模块语句顺序不正确的系统,因此有一个部分:

<IfModule mod_rewrite.so>
...
</IfModule>

在 apache 看到 LoadModule 语句之前它就出现了(通过所有的 Include 语句来追踪这一点很困难)。

如果有 IfModule 语句,请尝试将其注释掉,看看是否能解决问题。

答案2

这已经过时了,但因为没有可接受的答案。我遇到了类似的问题,相同的重写规则在生产环境中有效,但在开发环境中无效。发现开发环境中缺少此设置,添加它即可解决问题。

在 mod_jk.conf 中添加

JkMountCopy 'All'

相关内容