1

I have a CMS System that converts the ugly URLs into more friendly ones.

So far instanstance, instead of the page url being something like this:

/pagebase.php?id=3644

I have a url write setup for each page to make it more friendly.

For example:

RewriteRule ^/events$   /pagebase.php?id=3644 [I]

So that when the user types in domain.com/events they pull up above url.

This works for almost all pages except this one where I need to add additional query strings so I can do something like this.

www.domain.com/events?y=2010=&m=&1d=2

That would rewrite as

www.domain.com/pagebase.php?id=3366&y=2010=&m=&1d=2. 

The only problem is the url write match fails because it doesn't see the ?y=2010=&m=&1d=2 as a query string, it sees it as part of the url and fails.

I need to modify my rewrite file to allow query strings to be passed through.

I want to do something like RewriteRule ^/events-%QUERYSTRING% $ /pagebase.php?id=3644 + %QUERYSTRING% [I]

Where it removes the query string from the match but then appends it to the end of the written url. I just don't have enough knowledge on how url rewrites work to do this.

Here is an example of my rewrite file.

RewriteRule ^/events$   /pagebase.php?id=3644
RewriteRule ^/faqs$   /pagebase.php?id=3659
RewriteRule ^/gallery$   /pagebase.php?id=3645
RewriteRule ^/gifts$   /pagebase.php?id=3646

I need something that will work on all pages, I don't want to have to modify each rule to handle specific query strings, I just want a generic solutions that will pass the query strings through.

TroySteven
  • 4,885
  • 4
  • 32
  • 50
  • Append [L,QSA] to the RewriteRule statements. The "L" is to say Last (don't continue rewriting) and the "QSA" is Query String Append to add parameters to your URL – Bjørne Malmanger Jan 10 '13 at 23:14
  • That didn't seem to work. How would it look ? Like this RewriteRule ^/events$ /pagebase.php?id=3644 [L, QSA] – TroySteven Jan 11 '13 at 00:43
  • I see there can be a problem with combining a querystring with QSA. I think this would do the trick: `RewriteRule ^/events$ /pagebase.php?id=3644&%{QUERY_STRING} [L]` – Bjørne Malmanger Jan 13 '13 at 17:48

1 Answers1

1

You may try matching an optional query string, and have it appended by the [QSA] modifier:

RewriteRule ^/events(\?.*)?$   /pagebase.php?id=3644 [QSA,L]
RewriteRule ^/faqs(\?.*)?$     /pagebase.php?id=3659 [QSA,L]
RewriteRule ^/gallery(\?.*)?$  /pagebase.php?id=3645 [QSA,L]
RewriteRule ^/gifts(\?.*)?$    /pagebase.php?id=3646 [QSA,L]
marapet
  • 54,856
  • 12
  • 170
  • 184