我有一个托管在 linux el Cheapo 托管服务上的网站,我正在迁移到我的 Mac OS X 10.5 Leopard Server 服务器,运行 Apache 2.2.8 和 PHP 5.2.5 w/rewrite_module 启用AllowOverride All
,但我在文件中遇到以下行的问题.htaccess
:
RewriteEngine On
#RewriteRule ^view/([^/\.]+)/?$ /view.php?item=$1 [L]
#RewriteRule ^order/([^/\.]+)/?$ /order.php?item=$1 [L]
RewriteRule ^category/([^/\.]+)/?$ /category.php?category=$1 [L]
如您所见,我已经注释掉了and的RewriteRule
指令,所以我只处理. 当我尝试加载它时(我已经添加了调试代码来确认),但它会以空的形式出现。/view/
/order/
/category/
http://domain.tld/category/2/
category.php
$_SERVER['REQUEST_URI']
/category/2/
$_GET['category']
我通常对 .htaccess 文件和 mod_rewrite 指令进行故障排除很好,但由于某种原因,这让我感到困惑。
更新:我遵循了Josh 的建议mod_rewrite.log
,这是我尝试访问时倾倒的内容http://domain.tld/category/2/
:
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (2) init rewrite engine with requested uri /category/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (3) applying pattern '.*' to uri '/category/13'
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (1) pass through /category/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6aa98/subreq] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] add path info postfix: /Library/WebServer/Documents/tld.domain.www/category.php -> /Library/WebServer/Documents/tld.domain.www/category.php/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6aa98/subreq] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] strip per-dir prefix: /Library/WebServer/Documents/tld.domain.www/category.php/13 -> category.php/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6aa98/subreq] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] applying pattern '^category/([^/\.]+)/?$' to uri 'category.php/13'
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6aa98/subreq] (1) [perdir /Library/WebServer/Documents/tld.domain.www/] pass through /Library/WebServer/Documents/tld.domain.www/category.php
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] add path info postfix: /Library/WebServer/Documents/tld.domain.www/category.php -> /Library/WebServer/Documents/tld.domain.www/category.php/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] strip per-dir prefix: /Library/WebServer/Documents/tld.domain.www/category.php/13 -> category.php/13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] applying pattern '^category/([^/\.]+)/?$' to uri 'category.php/13'
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b5ea98/initial] (1) [perdir /Library/WebServer/Documents/tld.domain.www/] pass through /Library/WebServer/Documents/tld.domain.www/category.php
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (2) init rewrite engine with requested uri /13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (3) applying pattern '.*' to uri '/13'
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (1) pass through /13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] strip per-dir prefix: /Library/WebServer/Documents/tld.domain.www/13 -> 13
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (3) [perdir /Library/WebServer/Documents/tld.domain.www/] applying pattern '^category/([^/\.]+)/?$' to uri '13'
65.19.81.253 - - [22/Oct/2009:17:31:53 --0400] [domain.tld/sid#100aae0b0][rid#100b6ea98/subreq] (1) [perdir /Library/WebServer/Documents/tld.domain.www/] pass through /Library/WebServer/Documents/tld.domain.www/13
只需将其添加到您的 .htaccess 文件中
我几个小时都遇到同样的问题
我不知道为什么,但它在 OSX 上默认打开
它会产生您的错误,因为当您尝试加载category/时,它会找到category.php并将斜杠后的所有内容重定向到该文件
您可以访问 httpd.conf 吗?如果是这样,请添加到 httpd.conf:
并在您加载时发布该日志所说的内容
/category/2
。在您从中获得所需信息后将其删除 - 这非常浪费服务器资源。编辑:
感谢您的日志。某些东西正在将 URL 重写为:
/category.php/13
。还有其他 RewriteRules 吗?你在使用 FastCGI 吗?如果您重命名category.php
为其他名称,例如Category.php
ordisplay_category.php
怎么办?编辑2:
既然有些东西似乎正在重写
/category/(.*)
,/category/$1
我们不知道它是什么,你为什么不改变:至:
看看这是否有效?
我可能在这里是个白痴,但这不是预期的行为吗?Mod_rewrite 更改用于查找文件的 URL 内联,PHP 看到的环境变量通常不会更改。
我认为您必须解析 REQUEST_URI 字符串才能提取类别变量。
标记