Simple htaccess rewrite

Sorry for the noob question.

I’m trying to rewrite the following URL but can’t get it to work (I’ve read all the htaccess basics at apache.org).

http://www.example.com/util/doc.jsp?n=document-num_137298138853890.pdf

I’d be most grateful if anyone with more experience could point out where I’m going wrong. My htaccess code is:

RewriteBase /

RewriteCond %{QUERY_STRING} ^n=document-num_137298138853890\\.pdf$
RewriteRule ^util/doc.jsp$ http://www.example.com [R=permanent,L]

For future reference, it’s helpful if you tell us specifically how it doesn’t work. Does it send you to the wrong URL? Does it produce an error? Does it do nothing at all?

Working on speculation, I’d suggest two things. First, make sure you have RewriteEngine On in there before you try to rewrite anything. Second, add a question mark to the substitution URL – http://www.example.com?. Otherwise Apache will copy the original query string onto the substitution URL.

Hi Jeff, thanks for your response, fair point, I didn’t include any info on the specific error!

I just get a 404 error and the original url remains in the broswer (even after trying your suggestion).

The RewriteEngine is definitely on as the whole CMS relies on it and I have moved this rule first in the pecking order to ensure nothing else is interfering with it.

Well, the rewrite rule when used all by itself does indeed work, so something else in your htaccess must still be interfering. Can you post the whole htaccess?

Since you’re trying to rewrite a .jsp file, I’m guessing your server is Apache Tomcat, and not plain Apache. Can you find that out somehow?