我正忙着将生产 codeigniter 项目迁移到新服务器。当前设置已经运行良好近一年了,但在迁移到新的 LAMP 堆栈时,我在将 index.php 重写回 URL 时遇到了一个奇怪的问题。
我最初的想法是,这个问题更适合 SO,但是两个实例之间的代码完全相同,并且都运行 Debian 7.5 和 Apache 2.2.22,这让我认为这是我不知道的服务器配置差异。
这是mod_rewrite,如下所示
RewriteEngine On
RewriteBase /bookings/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
就像我所说的那样,这在当前设置中运行良好,但是在新服务器上,来自基础页面的链接总是被重写到同一页面。
我为两台服务器都打开了重写日志,而新服务器正在执行我无法解释的额外重写步骤。
当前服务器:
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/school -> /var/www/vhosts/domain.tld/html/bookings/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/school/event/1 -> school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-d' => matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] rewrite 'school/event/1' -> 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add per-dir prefix: index.php/school/event/1 -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] trying to replace prefix /var/www/vhosts/domain.tld/html/bookings/ with /bookings/
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (5) strip matching prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) add subst prefix: index.php/school/event/1 -> /bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] internal redirect with /bookings/index.php/school/event/1 [INTERNAL REDIRECT]
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/index.php -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
新服务器:
### First section is identical ###
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/school -> /var/www/vhosts/domain.tld/html/bookings/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/school/event/1 -> school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-d' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] rewrite 'school/event/1' -> 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add per-dir prefix: index.php/school/event/1 -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] trying to replace prefix /var/www/vhosts/domain.tld/html/bookings/ with /bookings/
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (5) strip matching prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) add subst prefix: index.php/school/event/1 -> /bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] internal redirect with /bookings/index.php/school/event/1 [INTERNAL REDIRECT]
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/index.php -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
### The extra redirect ###
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/ ->
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri ''
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/' pattern='!-d' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php -> index.php
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
如上所示,新服务器正确地执行了初始重定向,但有一个额外的部分始终返回 index.php。知道是什么原因造成的吗?我甚至不能 100% 确定问题出在 mod_rewrite 上。我已经没有其他选择了,而且我对 mod_rewrite 了解不多
答案1
我不知道是什么原因造成的,但我重新映像了服务器,重新安装了服务,问题就解决了。