令人沮丧的.htaccess URL重写问题


Frustrating .htaccess URL Rewriting issue

我正在与一位客户合作,我们最近刚刚将他们的网站从Godaddy(ew!)转移到Pair Networks。多年来,我个人和客户都使用过Pair,与他们有着丰富的合作经验。不幸的是,由于这是一个共享托管计划,URL重写技术支持不属于支持计划。

不管怎样,只要我们把站点移到根目录中的重写规则上,htaccess就不再工作了。.htaccess包含:

RewriteEngine On
RewriteRule ^((images|styles|scripts|documents)/*.*)$ $1 [L]
RewriteRule ^(admin/*)$ index.php/$1 [L]
RewriteRule ^([a-zA-Z0-9]+)$ page/id/$1
RewriteCond $1 !^(index'.php|robots'.txt|favicon'.ico)
RewriteRule ^(.*)$ index.php/$1 [L]

根据Apache的说法,错误是重定向过多,导致显示错误500。如果我评论一下:

#RewriteRule ^(.*)$ index.php/$1 [L]

然后加载默认页面(如果URL中没有指定,则index.php设置默认页面),但其他页面都无法加载。我不得不手动将每个URL格式的条目添加到.htaccess中,以保持网站的功能,结果是:

RewriteEngine On
RewriteRule ^((images|styles|scripts|documents)/*.*)$ $1 [L]    
RewriteRule ^(admin/*)$ index.php/$1 [L]
RewriteRule ^(admin/([a-zA-Z0-9]+))$ index.php/$1 [L]
RewriteRule ^(admin/([a-zA-Z0-9]+)/([a-zA-Z0-9]+))$ index.php/$1 [L]
RewriteRule ^(page/id/*)$ index.php/$1 [L]
RewriteRule ^(page/submit)$ index.php/page/submit [L]
RewriteRule ^([a-zA-Z0-9]+)$ index.php/page/id/$1
RewriteCond $1 !^(index'.php|robots'.txt|favicon'.ico)
#RewriteRule ^(.*)$ index.php/$1 [L]

该站点使用Codeigniter,因此预期的最终重写URL格式为:http://server/index.php/page/id/example以加载http://server/example

我在Pair服务器上有另一个客户端使用完全相同的CMS和相同的原始.htaccess大约6年了,没有任何问题,所以我有点惊讶为什么这会突然导致问题。它们甚至都使用相同版本的Apache和PHP(分别为2.2.22和5.3.8)。

有人知道这个问题可能是什么吗?我更希望不必像这样手动定义所有路线。

多年来,我们一直在使用一套非常相似的规则,没有遇到任何问题。除了我们在这行前面有两条RewriteCond规则来检查请求是否针对文件或目录:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]