SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

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

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    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.
    "First make it work. Then make it better."

  3. #3
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,278
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mingis View Post
    ...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?
    "First make it work. Then make it better."

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,084
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    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?
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •