mod_rewrite rule


I have a simple rule to take requests for html pages and pass them through a content management engine.

eg

news.html will be requested by apache as index.php?page=news
using
RewriteRule ^(.*)\.html$ index.php?page=$1 [L]

I now need to get the following working

news.html?a=1&b=2 as index.php?page=news&a=1&b=2

(so that the site works a= and b= will vary from page to page so the a= and b= can't be hard coded within the rule)

Nothing I've done with this gets it to work.
eg these fail
RewriteRule ^(.*)\.html(.*)$ index.php?page=$1&$2 [L]
LVL 3
jglyonsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

m1tk4Commented:
RewriteRule ^(.*)\.html(\?(.*))$ index.php?page=$1&$3
jglyonsAuthor Commented:
m1tk4 Not sure why you've gone to $3 but that rule breaks what worked at the start so that it now returns 404 page not found.
m1tk4Commented:
$3 because there are three sets of ()'s now. Turn on Rewrite logging and it will show you what's wrong with it.
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

m1tk4Commented:
RewriteRule ^(.*)\.html(\??(.*))$ index.php?page=$1&$3 [last]

sorry, missed one ?
caterham_wwwCommented:
You cannot access the QueryString from within a RewriteRule-pattern.

The case here: Just use the QSA-Flag (QueryString append), which adds the existing queryString to the new one:

RewriteRule ^(.*)\.html$ index.php?page=$1 [QSA,L]

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jglyonsAuthor Commented:

caterham_www GENIUS!  3 hours of tearing hair out and it was that simple.  Good answer thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.