Why is Apache ignoring my rewrite rule?

5,587

Try this:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^p=([0-9]+)$
RewriteRule ^appname/viewItem.akt$ http://appname.myserver.com/item/%1? [R,L]
  • %1 to back reference to Rewrite Condition
  • ? at the end of substitution to remove the rest of query string

But it seems you are mixing up mod_rewrite with mod_proxy. Which Apache version are you running?

Share:
5,587

Related videos on Youtube

Agvorth
Author by

Agvorth

Updated on September 18, 2022

Comments

  • Agvorth
    Agvorth almost 2 years

    I have an old application with URLs of the form...

    http://apps.myserver.com/appname/viewItem.akt?p=123
    

    I am replacing this old app with one that has URLs like...

    http://appname.myserver.com/item/123
    

    I've tried adding several different rewrite rules to httpd/httpd.conf and restarting the server, but I keep getting 404 errors.

    A couple things I've tried...

    RewriteEngine on
    
    RewriteRule ^.*viewItem.akt\?p=([0-9]*)$ http://appname.myserver.com/item/$1 [R]
    

    Or...

    RewriteRule ^/appname/viewItem.akt\?p=([0-9]*)$ http://appname.myserver.com/item/$1 [R]
    

    The result is always "The requested URL /appname/viewItem.akt was not found on this server", as if the rewrite rule weren't even there.

    What I'm getting in the access log is...

    [IP address] - - [09/Sep/2011:21:27:37 -0700] "GET /appname/viewItem.akt?p=1018 HTTP/1.0" 404 248
    

    I tested all my regexes in Rubular to make sure they match the incoming request.

    What am I missing?


    In case it's relevant, the old application was a Java app running under Tomcat, and I had a ProxyPass set up like this...

    (I'm showing these lines commented out, as they are when I'm trying to get the rewrite rule to work.)

    # ProxyPass /appname http://apps.myserver.com:8080/appname
    # ProxyPassReverse /appname http://apps.myserver.com:8080/appname
    

    But that shouldn't matter right? As long as my rewrite rule matches the request it should send it along properly, shouldn't it?

    • womble
      womble almost 13 years
      Error logs and rewrite logs would be instructive.
  • Agvorth
    Agvorth almost 13 years
    Thanks. Actually, I only mentioned the Proxy settings because they relate to the previous app that I'm trying to decommission on the off chance that they're relevant somehow. They are commented out.
  • Agvorth
    Agvorth almost 13 years
    Apache version is 2.2.3