mod_rewrite rule

Posted on 2006-04-15
Medium Priority
Last Modified: 2010-05-18

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


news.html will be requested by apache as index.php?page=news
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]
Question by:jglyons
  • 3
  • 2
LVL 15

Expert Comment

ID: 16461242
RewriteRule ^(.*)\.html(\?(.*))$ index.php?page=$1&$3

Author Comment

ID: 16461277
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.
LVL 15

Expert Comment

ID: 16461326
$3 because there are three sets of ()'s now. Turn on Rewrite logging and it will show you what's wrong with it.
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

LVL 15

Expert Comment

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

sorry, missed one ?
LVL 27

Accepted Solution

caterham_www earned 1800 total points
ID: 16461349
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]

Author Comment

ID: 16461474

caterham_www GENIUS!  3 hours of tearing hair out and it was that simple.  Good answer thank you.

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question