Apache的mod_rewrite有多个参数 [英] Apache mod_rewrite with multiple parameters

查看:125
本文介绍了Apache的mod_rewrite有多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been struggling to get the following rewrite working

^/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文件

I know that mod_rewrite is working. I know that it is reading the .htaccess file, I'm just not seeing any redirecting happening. Here's what I have in my .htaccess file

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

任何帮助将大大AP preciated。我想这是简单的东西,但我一直没能弄明白。在Apache的错误日志和访问日志中没有错误只是记录404。

Any help would be greatly appreciated. I imagine it is something simple, but I have not been able to figure it out. No errors in the Apache error log, and the access log is simply recording a 404.

推荐答案

URL查询是不URL路径的一部分,因此不能用的 重写规则 。在这里,你需要一个额外的 的RewriteCond 指令。此外,当您在.htaccess文件使用mod_rewrite时,每个目录路径preFIX正在测试的规则删除之前和运​​用规则之后添加回来。所以你的情况,你需要从你的模式删除前导 /

The URL query is not part of the URL path and thus can not be processed with RewriteRule. Here you need an additional RewriteCond directive. Additionally, when you use mod_rewrite in an .htaccess file, the per-directory path prefix is removed before testing the rules and appended back after applying a rule. So in your case you would need to remove the leading / from your pattern.

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

这篇关于Apache的mod_rewrite有多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆