为什么这个mod_rewrite RewriteRule指令不能在.htaccess文件中工作?

我有一个网站,托pipe在一个Linux el cheapo托pipe服务,我正在迁移到我的Mac OS X 10.5豹服务器运行Apache 2.2.8和PHP 5.2.5瓦特/ 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] 

正如你所看到的,我已经注释到了/view//order/RewriteRule指令,所以我只处理/category/ 。 当我尝试加载http://domain.tld/category/2/它运行category.php (我添加了debugging代码来确认),但$_SERVER['REQUEST_URI']通过/category/2/$_GET['category']通过为空。

我通常罚款解决.htaccess文件和mod_rewrite指令,但这一个让我难住的原因。

更新 :我遵循乔希的build议 ,这里是什么被转储到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文件

 Options -MultiViews 

我几个小时都有同样的问题

我不知道为什么,但它在OSX上默认打开

它会产生你的错误,因为当你尝试加载类别/它find了category.php并redirect斜杠后的所有内容到该文件

你有访问httpd.conf? 如果是的话请添加到httpd.conf中:

 RewriteLog "/tmp/mod_rewrite.log" RewriteLogLevel 3 

并发布什么日志说当你加载/category/2 。 从您的信息中获得所需的信息后,将其删除 – 这非常浪费服务器资源。

编辑:

感谢日志。 有些东西正在将URL重写为: /category.php/13 。 任何其他RewriteRules? 你在使用FastCGI吗? 如果将category.php重命名为其他内容,例如Category.phpdisplay_category.php会怎么样?

EDIT2:

由于某些东西好像是将/category/(.*)改写成/category/$1 ,而我们不知道它是什么,为什么不改变:

 RewriteRule ^category/([^/\.]+)/?$ /category.php?category=$1 [L] 

至:

 RewriteRule ^category.php/([^/\.]+)/?$ /category.php?category=$1 [L] 

看看是否有用?

我可能在这里是一个白痴,但不是预期的行为? Mod_rewrite更改内联URL以查找文件,PHP看到的环境variables通常不会更改。

我认为你必须parsingREQUEST_URIstring来拉出类别variables。

标记