Apache mod_rewrite有多个参数

时间:2010-01-05 19:22:01

标签: apache mod-rewrite

我一直在努力让以下重写工作

^/agatedepot/([0-9.]+)/([0-9a-zA-Z._]+)\?doc-id=([0-9a-zA-Z._\-]+)

/agateDepot.php?date=$1&filename=$2&doc-id=$3

我知道mod_rewrite正在运行。我知道它正在读取.htaccess文件,我只是没有看到任何重定向发生。这是我的.htaccess文件中的内容

RewriteEngine On
RewriteRule ^/agatedepot/([0-9.]+)/([0-9a-zA-Z._]+)\?doc-id=([0-9a-zA-Z._\-]+) /agateDepot.php?date=$1&filename=$2&doc-id=$3

非常感谢任何帮助。我想这很简单,但我无法弄明白。 Apache错误日志中没有错误,访问日志只记录404。

3 个答案:

答案 0 :(得分:3)

URL查询不是URL路径的一部分,因此无法使用RewriteRule进行处理。在这里,您需要额外的RewriteCond directive。此外,在.htaccess文件中使用mod_rewrite时,将在测试规则之前删除每个目录的路径前缀,并在应用规则后附加回来。因此,在您的情况下,您需要从模式中删除前导/

RewriteCond %{QUERY_STRING} ^doc-id=([0-9a-zA-Z._\-]+)$
RewriteRule ^agatedepot/([0-9.]+)/([0-9a-zA-Z._]+)$ agateDepot.php?date=$1&filename=$2&doc-id=%1

答案 1 :(得分:0)

问号?标记QueryString的开头,因此RewriteRule不对其进行分析。您应该替换?或使用RewriteCond %{QUERY_STRING} ...进行分析。

答案 2 :(得分:-1)

尝试添加RewriteBase /并跳过第一个斜杠(即^agatedepot...