Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Error logs and rewrite logs would be instructive. –  womble Sep 10 '11 at 6:01
add comment

3 Answers

up vote 3 down vote accepted

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|improve this answer
    
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 '11 at 20:36
    
Apache version is 2.2.3 –  Agvorth Sep 10 '11 at 21:24
    
Thanks, that worked. –  Agvorth Sep 10 '11 at 22:12
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.