views:

470

answers:

2

Hi,

I've tested the following Mod Rewrite on MAMP, but for some reason, it fails on LAMP. Any idea of what I am doing wrong?

RewriteEngine on
RewriteCond %{QUERY_STRING} ^newParamA=(.*)&newParamB=([0-9]*)$
RewriteRule ^newfolder/newsubfolder/$ oldfolder/oldsubfolder\.php?oldParamC=%1\&oldParamD=%2 [QSA,L]

The idea is that a query such as

http://domain.com/newfolder/newsubfolder/?newParamA=query&newParamB=111

will successfully map to:

http://domain.com/oldfolder/oldsubfolder/?oldParamC=query&oldParamD=111
A: 

In answer to Gumbo's comment (Are you using the same config)

Yep - latest version of Apache, with mod_rewrite enabled - It seems that it doesn't like the RewriteCond - if I comment that out, at least the path redirect works. When I uncomment the RewriteCond, I get "Not found" error.

Yes - That all works. If I comment out rewritecond, newfolder/newsubfolder map to oldfolder/oldsubfolderI just need to map the parameters, but it doesn't seem to like rewriteCond
A: 

I currently don’t know what could cause this behavior. But you could try one of these:

RewriteCond %{QUERY_STRING} ^newParamA=([^&]*)&newParamB=([0-9]*)$
RewriteRule ^newfolder/newsubfolder/$ oldfolder/oldsubfolder.php?oldParamC=%1&oldParamD=%2 [QSA,L]

RewriteCond %{QUERY_STRING} (^|&)newParamA=([^&]*)&newParamB=([0-9]*)($|&)
RewriteRule ^newfolder/newsubfolder/$ oldfolder/oldsubfolder.php?oldParamC=%2&oldParamD=%3 [QSA,L]

Or even:

RewriteCond %{QUERY_STRING} (^|([^&]*&)*)newParamA=([^&]*)(.*)
RewriteCond %3&%1&%4 ^([^&]*)(&[^&]*)*&newParamB=([0-9]*)
RewriteRule ^newfolder/newsubfolder/$ oldfolder/oldsubfolder.php?oldParamC=%1&oldParamD=%3 [QSA,L]
Gumbo