1

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.

3
  • 1
    This question is better suited to ServerFault. Commented Jan 5, 2010 at 19:25
  • You should give an example for concrete URL for tests. Commented Jan 5, 2010 at 19:31
  • sure /agatedepot/2010.01.03/a_bunch_of_text.txt?doc-id=xt.l.nfl.com.7182032 Commented Jan 5, 2010 at 19:33

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly. Thanks so much!
If you just want to append the original requested query to the new one, you could also set the QSA flag.
0

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

Comments

-1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.