开发者

Apache mod_rewrite with multiple parameters

I've been struggling to get the following rewrite working

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

to

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

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

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.


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


Question mark ? marks the start of the QueryString, hence it's not analyzed by the RewriteRule. You should replace the ? or analyze it with RewriteCond %{QUERY_STRING} ....


Try to add RewriteBase / and skip the first slash (i.e. ^agatedepot...)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜