【发布时间】:2012-04-03 02:17:37
【问题描述】:
我正在与一位客户合作,我们最近将他们的网站从 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)。
有人对问题可能是什么有想法吗?我宁愿不必像这样手动定义所有路线。
【问题讨论】:
标签: php codeigniter url-rewriting