linux – 为什么这个mod_rewrite RewriteRule指令在.htaccess文件中不起作用?

前端之家收集整理的这篇文章主要介绍了linux – 为什么这个mod_rewrite RewriteRule指令在.htaccess文件中不起作用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个托管在 linux el cheapo托管服务上的网站,我正在迁移到运行Apache 2.2.8&的Mac OS X 10.5 Leopard Server服务器. 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]

正如您所看到的,我已经为/ view /和/ order /注释掉了RewriteRule指令,因此我只处理/ category /.当我尝试加载http://domain.tld/category/2/时,它运行category.PHP(我添加了调试代码以确认),但$_SERVER [‘REQUEST_URI’]来自/ category / 2 /和$_GET [‘category’]是空的.

我通常对故障排除.htaccess文件和mod_rewrite指令很好,但是由于某种原因,这个让我难过.

更新:我跟着Josh’s suggestion,这是我尝试访问http://domain.tld/category/2/时转储到mod_rewrite.log的内容

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上打开了

它产生你的错误,因为当你尝试加载类别/它找到category.PHP并将斜杠后的所有内容重定向到该文件

猜你在找的Linux相关文章