1

I have a website that I successfully use the following url rewrite on:

RewriteRule ^(.*)_r-(.*)/calculator.html$ /calcadd.php?rest_id=$1 [L]

As my website has evolved I've decided it would be helpful to be able to pass some additional parameters to this page. So I tried to update the url to include a variable after the .html. Here's what I tried:

    RewriteRule ^(.*)_r-(.*)/calculator.html?ids=(.*)$ /calcadd.php?rest_id=$1&ids=$3 [L]

This doesn't work, I get a page not found error. And just in case it wasn't clear, this is NOT a mod_rewrite isn't enabled or whatever problem. All my other rewrites work just fine, so mod_rewrite is enabled, allow override is ALL, etc.

Thanks!

user2874270
  • 1,312
  • 2
  • 18
  • 31

3 Answers3

2

You just need a QSA flag here to preserve original query while adding new query parameters:

RewriteRule ^(.*)_r-(.*)/calculator\.html$ /calcadd.php?rest_id=$1 [L,NC,QSA]

Also remember that you cannot match query string in RewriteRule.

anubhava
  • 761,203
  • 64
  • 569
  • 643
0

The RewriteRule only consideres the requested url without the querystring by default. You need a RewriteCond to achieve what you want:

RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^(.*)_r-(.*)/calculator.html$ /calcadd.php?rest_id=$1&%1 [L]

untested.

With %1, %2, etc. you can inject the patterns matched in the correspondent parenthesized patterns in the RewriteCond statement in your RewriteRule.

Mario A
  • 3,286
  • 1
  • 17
  • 22
0

Just leave it the way it was and use this. QSA flag means Query String Append. It will will automatically add the query sting to the end of your rewrite.

RewriteRule ^(.*)_r-(.*)/calculator.html$ /calcadd.php?rest_id=$1 [QSA,L]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95