views:

92

answers:

3

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.

A: 

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

Felix Kling
A: 

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} ....

Y. Shoham
+2  A: 

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
Gumbo
Worked perfectly. Thanks so much!
GrumpyCanuck
If you just want to append the original requested query to the new one, you could also set the *QSA* flag.
Gumbo