1

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?

1
  • Error logs and rewrite logs would be instructive.
    – womble
    Sep 10, 2011 at 6:01

3 Answers 3

4

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?

2
  • 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
    Sep 10, 2011 at 20:36
  • Apache version is 2.2.3
    – Agvorth
    Sep 10, 2011 at 21:24
0

Are you sure that mod_rewrite is correctly loaded?

Otherwise, using the directive RewriteLog with an according RewriteLogLevel should help you figuring out if your RewriteRule is taken into account while requesting your page, and if the regular expression matches or not.

0

I don't know if this suits your need, but these things drive me crazy too. I always try to simplify as much as I can.

This appears to work in my tests:
RewriteRule p=([0-9]*)$ http://appname.myserver.com/item/$1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .